Skip to content

Commit

Permalink
Complete module template
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 24, 2017
1 parent c29d78b commit 99a2716
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 21 deletions.
1 change: 1 addition & 0 deletions htdocs/langs/en_US/modulebuilder.lang
Expand Up @@ -40,6 +40,7 @@ PathToModuleDocumentation=Path to file of module/application documentation
SpaceOrSpecialCharAreNotAllowed=Spaces or special characters are not allowed.
FileNotYetGenerated=File not yet generated
SpecificationFile=File with business rules
LanguageFile=File for language
ConfirmDeleteProperty=Are you sure you want to delete the property <strong>%s</strong> ? This will change code in PHP class but also remove column from table definition of object.
NotNull=Not NULL
SearchAll=Used for 'search all'
Expand Down
60 changes: 58 additions & 2 deletions htdocs/modulebuilder/index.php
Expand Up @@ -146,7 +146,10 @@
'MyModule'=>$modulename,
'MYMODULE'=>strtoupper($modulename),
'My module'=>$modulename,
'htdocs/modulebuilder/template/'=>strtolower($modulename),
'my module'=>$modulename,
'Mon module'=>$modulename,
'mon module'=>$modulename,
'htdocs/modulebuilder/template/'=>strtolower($modulename),
'---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
);

Expand Down Expand Up @@ -293,7 +296,10 @@
'MyModule'=>$module,
'MYMODULE'=>strtoupper($module),
'My module'=>$module,
'htdocs/modulebuilder/template/'=>strtolower($modulename),
'my module'=>$module,
'mon module'=>$module,
'Mon module'=>$module,
'htdocs/modulebuilder/template/'=>strtolower($modulename),
'myobject'=>strtolower($objectname),
'MyObject'=>$objectname
);
Expand Down Expand Up @@ -908,6 +914,11 @@
$head2[$h][2] = 'specifications';
$h++;

$head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread?'@'.$dirread:'');
$head2[$h][1] = $langs->trans("Languages");
$head2[$h][2] = 'languages';
$h++;

$head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread?'@'.$dirread:'');
$head2[$h][1] = $langs->trans("Objects");
$head2[$h][2] = 'objects';
Expand Down Expand Up @@ -1151,6 +1162,51 @@
}
}

if ($tab == 'languages')
{
if ($action != 'editfile' || empty($file))
{
$langfiles=dol_dir_list(dol_buildpath($modulelowercase.'/langs', 0), 'files', 1, '\.lang$');

foreach ($langfiles as $langfile)
{
$pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
print '<span class="fa fa-file"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong>'.$pathtofile.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
}
}
else
{
// Edit text language file

//print $langs->trans("UseAsciiDocFormat").'<br>';

$fullpathoffile=dol_buildpath($file, 0);

$content = file_get_contents($fullpathoffile);

// New module
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="savefile">';
print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
print '<input type="hidden" name="tab" value="'.$tab.'">';
print '<input type="hidden" name="module" value="'.$module.'">';

$doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'text'));
print '<br>';
print '<center>';
print '<input type="submit" class="button" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</center>';

print '</form>';
}
}

if ($tab == 'objects')
{
$head3 = array();
Expand Down
84 changes: 68 additions & 16 deletions htdocs/modulebuilder/template/class/actions_mymodule.class.php
Expand Up @@ -78,13 +78,9 @@ public function doActions($parameters, &$object, &$action, $hookmanager)

$error = 0; // Error counter

/*
print_r($parameters);
print_r($object);
echo "action: " . $action;
*/

if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
{


}
Expand Down Expand Up @@ -115,14 +111,9 @@ public function doMassActions($parameters, &$object, &$action, $hookmanager)

$error = 0; // Error counter

/*
print_r($parameters);
print_r($object);
echo "action: " . $action;
*/

if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'

/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
{
foreach($parameters['toselect'] as $objectid)
{
// Do action on each object id
Expand Down Expand Up @@ -156,7 +147,8 @@ public function addMoreMassActions($parameters, &$object, &$action, $hookmanager

$error = 0; // Error counter

if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext'
/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
{
$this->resprints = '<option value="0"'.($disabled?' disabled="disabled"':'').'>'.$langs->trans("MyModuleMassAction").'</option>';
}
Expand All @@ -171,4 +163,64 @@ public function addMoreMassActions($parameters, &$object, &$action, $hookmanager



/**
* Execute action
*
* @param array $parameters Array of parameters
* @param Object $object Object output on PDF
* @param string $action 'add', 'update', 'view'
* @return int <0 if KO,
* =0 if OK but we want to process standard actions too,
* >0 if OK and we want to replace standard actions.
*/
function beforePDFCreation($parameters, &$object, &$action)
{
global $langs,$conf;
global $hookmanager;

$outputlangs=$langs;

$ret=0; $deltemp=array();
dol_syslog(get_class($this).'::executeHooks action='.$action);

/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
{

}

return $ret;
}

/**
* Execute action
*
* @param array $parameters Array of parameters
* @param Object $pdfhandler PDF builder handler
* @param string $action 'add', 'update', 'view'
* @return int <0 if KO,
* =0 if OK but we want to process standard actions too,
* >0 if OK and we want to replace standard actions.
*/
function afterPDFCreation($parameters, &$pdfhandler, &$action)
{
global $langs,$conf;
global $hookmanager;

$outputlangs=$langs;

$ret=0; $deltemp=array();
dol_syslog(get_class($this).'::executeHooks action='.$action);

/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext1' or 'somecontext2'
{

}

return $ret;
}

/* Add here any other hooked methods... */

}
1 change: 1 addition & 0 deletions htdocs/modulebuilder/template/core/boxes/README.md
@@ -0,0 +1 @@
Directory where widgets files are stored.
Expand Up @@ -95,7 +95,7 @@ public function __construct($db)
'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)
'css' => array('/mymodule/css/mymodule.css.php'), // Set this to relative path of css file if module has its own css file
'js' => array('/mymodule/js/mymodule.js.php'), // Set this to relative path of js file if module must load a js on all pages
'hooks' => array('hookcontext1','hookcontext2') // Set here all hooks context managed by module. You can also set hook context 'all'
'hooks' => array('hookcontext1','hookcontext2') // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context 'all'
);

// Data directories to create when module is enabled.
Expand Down Expand Up @@ -305,15 +305,18 @@ public function __construct($db)
*/
public function init($options='')
{
$sql = array();

$this->_load_tables('/mymodule/sql/');

// Create extrafields
include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);

//$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty');
//$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'string', 1, 10, 'project');
//$param=array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3'));
//$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'select', 1, 3, 'thirdparty', 0, 1, '', $param, 1);

$sql = array();

return $this->_init($sql, $options);
}
Expand Down
1 change: 1 addition & 0 deletions htdocs/modulebuilder/template/core/triggers/README.md
@@ -0,0 +1 @@
Directory where triggers files are stored.

0 comments on commit 99a2716

Please sign in to comment.