diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 77502f1737ca751343b09eec4e5506ca4e7e0da9..6711ed2825f6b40d898c909dba5fde63079b793b 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -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) { @@ -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. * diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index af9ab67d8fe16731c3605076ccce727600987b99..0741dcef978c75012a3b0b7884b85882f5b5153b 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -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'].","; diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 9a7fbb7b3bc9c60cb4d1052c29c1aaf47a9cf337..a3ba8a7455b0959768890b17d6eaa20039f10cea 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -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. diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 4afaf136e199e8c6cf03d4a7ff73736e85de1f04..18d543c79330b9d5222cd218ec6f8e1baadcd64d 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -217,6 +217,46 @@ if ($dirins && $action == 'initobject' && $module && $objectname) 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'; + } } } } diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index f8882b68c563d01f66d2b6f3636e24b2db93d7a0..a68e0ff0da563b2a5ef90a4853714f2e4e4c8351 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -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 diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 8c7da67b7ab7688d401b777ca0342616d65cd50c..3943e1b9314f4bba4a55504677d7f62ab99194c4 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -226,7 +226,7 @@ class modMyModule extends DolibarrModules // 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', @@ -238,12 +238,12 @@ class modMyModule extends DolibarrModules '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', @@ -255,8 +255,7 @@ class modMyModule extends DolibarrModules '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', @@ -268,7 +267,6 @@ class modMyModule extends DolibarrModules '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 */ diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 9d1019affee4da9bd4833a4c5dea5bfcec6bac81..6430944bec735ccfc2e1d14716ea551017bfcff8 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -123,7 +123,8 @@ foreach($object->fields as $key => $val) $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))