Skip to content

Commit

Permalink
Debug modulebuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 21, 2017
1 parent 6830fe4 commit f64a996
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
21 changes: 19 additions & 2 deletions htdocs/core/lib/files.lib.php
Expand Up @@ -448,12 +448,12 @@ function dol_filemtime($pathoffile)
* Make replacement of strings into a file.
*
* @param string $srcfile Source file (can't be a directory)
* @param array $arrayreplacement Array with strings to replace
* @param array $arrayreplacement Array with strings to replace. Example: array('valuebefore'=>'valueafter', ...)
* @param string $destfile Destination file (can't be a directory). If empty, will be same than source file.
* @param int $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @param int $indexdatabase Index new file into database.
* @return int <0 if error, 0 if nothing done (dest file already exists), >0 if OK
* @see dolCopyr
* @see dolCopyr dolReplaceRegExInFile
*/
function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0)
{
Expand Down Expand Up @@ -514,6 +514,23 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0,
return 1;
}

/**
* Make replacement of strings into a file.
*
* @param string $srcfile Source file (can't be a directory)
* @param array $arrayreplacement Array with strings to replace. Example: array('valuebefore'=>'valueafter', ...)
* @param string $destfile Destination file (can't be a directory). If empty, will be same than source file.
* @param int $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @param int $indexdatabase Index new file into database.
* @return int <0 if error, 0 if nothing done (dest file already exists), >0 if OK
* @see dolCopyr dolReplaceInFile
*/
function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0)
{
// TODO

}

/**
* Copy a file to another file.
*
Expand Down
2 changes: 2 additions & 0 deletions htdocs/core/lib/modulebuilder.lib.php
Expand Up @@ -77,6 +77,8 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask)
$i++;
$typephp='';
$texttoinsert.= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',";
$texttoinsert.= " 'visible'=>".$val['visible'].",";
$texttoinsert.= " 'enabled'=>".$val['enabled'].",";
if ($val['position']) $texttoinsert.= " 'position'=>".$val['position'].",";
if ($val['notnull']) $texttoinsert.= " 'notnull'=>".$val['notnull'].",";
if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].",";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/modulebuilder.lang
Expand Up @@ -13,7 +13,7 @@ FilesForObjectInitialized=Files for new object '%s' initialized
FilesForObjectUpdated=Files for object '%s' updated (.sql files and .class.php file)
ModuleBuilderDescdescription=Enter here all general information that describe your module
ModuleBuilderDescspecifications=You can enter here a long text to describe the specifications of your module that is not already structured into other tabs. So you have within easy reach all the rules to develop. Also this text content will be included into the generated documentation (see last tab). You can use Markdown format, but it is recommanded to use Asciidoc format (Comparison between .md and .asciidoc: http://asciidoctor.org/docs/user-manual/#compared-to-markdown)
ModuleBuilderDescobjects=Define here the objects you want to manage with your module. A sql file, a page to list them, to create/edit/view a card and an API will be generated.
ModuleBuilderDescobjects=Define here the objects you want to manage with your module. A CRUD DAO class, SQL files, page to list record of objects, to create/edit/view a record and an API will be generated.
ModuleBuilderDescmenus=This tab is dedicated to define menu entries provided by your module.
ModuleBuilderDescpermissions=This tab is dedicated to define the new permissions you want to provide with your module.
ModuleBuilderDesctriggers=This is the view of triggers provided by your module. To include code executed when a triggered business event is launched, just edit this file.
Expand Down
40 changes: 40 additions & 0 deletions htdocs/modulebuilder/index.php
Expand Up @@ -217,6 +217,46 @@
else
{
// Copy is ok
if ($destfile == 'class/'.$objectname.'.txt')
{
// Regenerate left menu entry in descriptor
$stringtoadd='';
// TODO Loop on each .txt file in class dir.
$stringtoadd.="
\t\t\$this->menu[\$r++]=array(
'fk_menu'=>'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'List MyObject',
'mainmenu'=>'mymodule',
'leftmenu'=>'mymodule_myobject',
'url'=>'/mymodule/myobject_list.php',
'langs'=>'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>1100+\$r,
'enabled'=>'\$conf->mymodule->enabled', // Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
\t\t\$this->menu[\$r++]=array(
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=mymodule_myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'New MyObject',
'mainmenu'=>'mymodule',
'leftmenu'=>'mymodule_myobject',
'url'=>'/mymodule/myobject_card.php?action=create',
'langs'=>'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>1100+\$r,
'enabled'=>'\$conf->mymodule->enabled', // Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
";
$moduledescriptorfile=$dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
// TODO Allow a replace with regex using dolReplaceRegexInFile
dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */"));

// Add module descriptor to list of files to replace "MyObject' string with real name of object.
$filetogenerate[]='core/modules/mod'.$module.'.class.php';
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions htdocs/modulebuilder/template/class/myobject.class.php
Expand Up @@ -63,12 +63,12 @@ class MyObject extends CommonObject
* @var array Array with all fields and their property
*/
public $fields=array(
'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'position'=>10, 'notnull'=>true, 'index'=>true, 'searchall'=>1, 'comment'=>'Reference of object'),
'entity'=>array('type'=>'integer', 'label'=>'Entity', 'notnull'=>true, 'index'=>true),
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'searchall'=>1),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'notnull'=>true, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'notnull'=>true, 'position'=>500),
'status'=>array('type'=>'integer', 'label'=>'Status', 'index'=>true, 'position'=>1000),
'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>true, 'index'=>true, 'searchall'=>1, 'comment'=>'Reference of object'),
'entity'=>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>true, 'index'=>true),
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'searchall'=>1),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'status'=>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
);
// END MODULEBUILDER PROPERTIES

Expand Down
10 changes: 4 additions & 6 deletions htdocs/modulebuilder/template/core/modules/modMyModule.class.php
Expand Up @@ -226,7 +226,7 @@ public function __construct($db)

// Example to declare a new Top Menu entry and its Left menu entry:
/* BEGIN MODULEBUILDER TOPMENU */
$this->menu[$r]=array( 'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
$this->menu[$r++]=array('fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'top', // This is a Top menu entry
'titre'=>'MyModule',
'mainmenu'=>'mymodule',
Expand All @@ -238,12 +238,12 @@ public function __construct($db)
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
// $r++;

/* END MODULEBUILDER TOPMENU */

// Example to declare a Left Menu entry into an existing Top menu entry:
/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'List MyObject',
'mainmenu'=>'mymodule',
Expand All @@ -255,8 +255,7 @@ public function __construct($db)
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=mymodule&fk_leftmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'New MyObject',
'mainmenu'=>'mymodule',
Expand All @@ -268,7 +267,6 @@ public function __construct($db)
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
END MODULEBUILDER LEFTMENU MYOBJECT */


Expand Down
3 changes: 2 additions & 1 deletion htdocs/modulebuilder/template/myobject_list.php
Expand Up @@ -123,7 +123,8 @@
$arrayfields=array();
foreach($object->fields as $key => $val)
{
$arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>1);
// If $val['visible']==0, then we never show the field
if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled']);
}
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
Expand Down

0 comments on commit f64a996

Please sign in to comment.