diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index e6f36b25d47..4e5cbb92c02 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -128,17 +128,19 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = $i++; $texttoinsert.= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',"; $texttoinsert.= " 'enabled'=>".($val['enabled']!=''?$val['enabled']:1).","; - $texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).","; $texttoinsert.= " 'position'=>".($val['position']!=''?$val['position']:50).","; - $texttoinsert.= " 'notnull'=>".($val['notnull']!=''?$val['notnull']:-1).","; + $texttoinsert.= " 'notnull'=>".(empty($val['notnull'])?0:$val['notnull']).","; + $texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).","; + if ($val['noteditable']) $texttoinsert.= " 'noteditable'=>'".$val['noteditable']."',"; if ($val['default']) $texttoinsert.= " 'default'=>'".$val['default']."',"; if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].","; + if ($val['foreignkey']) $texttoinsert.= " 'foreignkey'=>'".$val['foreignkey']."',"; if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].","; if ($val['isameasure']) $texttoinsert.= " 'isameasure'=>'".$val['isameasure']."',"; - if ($val['foreignkey']) $texttoinsert.= " 'foreignkey'=>'".$val['foreignkey']."',"; + if ($val['css']) $texttoinsert.= " 'css'=>'".$val['css']."',"; if ($val['help']) $texttoinsert.= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; - if ($val['comment']) $texttoinsert.= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\","; if ($val['showoncombobox']) $texttoinsert.= " 'showoncombobox'=>'".$val['showoncombobox']."',"; + if ($val['disabled']) $texttoinsert.= " 'disabled'=>'".$val['disabled']."',"; if ($val['arrayofkeyval']) { $texttoinsert.= " 'arrayofkeyval'=>array("; @@ -149,8 +151,10 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = $texttoinsert.="'".$key2."'=>'".$val2."'"; $i++; } - $texttoinsert.= ")"; + $texttoinsert.= "),"; } + if ($val['comment']) $texttoinsert.= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\""; + $texttoinsert.= "),\n"; } } diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 59d16eba2fc..4a0e0daf5c1 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -129,3 +129,9 @@ IncludeRefGeneration=The reference of object must be generated automatically IncludeRefGenerationHelp=Check this if you want to include code to manage the generation automatically of the reference IncludeDocGeneration=I want to generate some documents from the object IncludeDocGenerationHelp=If you check this, some code will be generated to add a "Generate document" box on the record. +ShowOnCombobox=Show value into combobox +KeyForTooltip=Key for tooltip +CSSClass=CSS Class +NotEditable=Not editable +ForeignKey=Foreign key +TypeOfFieldsHelp=Type of fields:
varchar(99), double(24,8), real, text, html, datetime, timestamp, integer, integer:ClassName:relativepath/to/classfile.class.php:1 (1 means we add a + button after the combo to create the record) \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index a6df5f9db43..7fffdfcd50d 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -810,18 +810,23 @@ if ($dirins && $action == 'initobject' && $module && $objectname) //'class/api_mymodule.class.php'=>'class/api_'.strtolower($module).'.class.php', ); - if (GETPOST('includerefgeneration', 'int')) + if (GETPOST('includerefgeneration', 'aZ09')) { + dol_mkdir($destdir.'/core/modules/'.strtolower($module)); + $filetogenerate += array( - 'core/modules/myobject/mod_myobject_advanced.php'=>'core/modules/'.strtolower($objectname).'/mod_'.strtolower($objectname).'_advanced.php', - 'core/modules/myobject/mod_myobject_standard.php'=>'core/modules/'.strtolower($objectname).'/mod_'.strtolower($objectname).'_standard.php', - 'core/modules/myobject/modules_myobject.php'=>'core/modules/'.strtolower($objectname).'/mod_'.strtolower($objectname).'_advanced.php', + 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php', + 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php', + 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php', ); } - if (GETPOST('includedocgeneration', 'int')) + if (GETPOST('includedocgeneration', 'aZ09')) { + dol_mkdir($destdir.'/core/modules/'.strtolower($module)); + dol_mkdir($destdir.'/core/modules/'.strtolower($module).'/doc'); + $filetogenerate += array( - 'core/modules/myobject/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($objectname).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php' + 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php' ); } @@ -843,8 +848,21 @@ if ($dirins && $action == 'initobject' && $module && $objectname) } } - //if (! $error) // If there is error copying 1 file, we still have to make the replacement - //{ + // Edit the class 'class/'.strtolower($objectname).'.class.php' + if (GETPOST('includerefgeneration', 'aZ09')) { + // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>'' + $arrayreplacement = array('/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"); + //var_dump($arrayreplacement);exit; + //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit; + dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1); + } + + // Edit the setup file and the card page + if (GETPOST('includedocgeneration', 'aZ09')) { + // TODO + // dolReplaceInFile(); + } + // Scan for object class files $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$'); @@ -917,15 +935,12 @@ if ($dirins && $action == 'initobject' && $module && $objectname) // Add module descriptor to list of files to replace "MyObject' string with real name of object. $filetogenerate[]='core/modules/mod'.$module.'.class.php'; - - // TODO } - //} } if (! $error) { - // Edit PHP files + // Edit PHP files to make replacement foreach($filetogenerate as $destfile) { $phpfileval['fullname'] = $destdir.'/'.$destfile; @@ -970,6 +985,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) if (! $error) { setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null); + $tabobj = $objectname; } } @@ -1198,14 +1214,15 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql', 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql', 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql', + 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql', 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php', 'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png', 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php', 'class/api_myobject.class.php'=>'class/api_'.strtolower($module).'.class.php', - 'core/modules/myobject/mod_myobject_advanced.php'=>'core/modules/'.strtolower($objectname).'/mod_'.strtolower($objectname).'_advanced.php', - 'core/modules/myobject/mod_myobject_standard.php'=>'core/modules/'.strtolower($objectname).'/mod_'.strtolower($objectname).'_standard.php', - 'core/modules/myobject/modules_myobject.php'=>'core/modules/'.strtolower($objectname).'/mod_'.strtolower($objectname).'_advanced.php', - 'core/modules/myobject/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($objectname).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php' + 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php', + 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php', + 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php', + 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php' ); $resultko = 0; @@ -2460,7 +2477,7 @@ elseif (! empty($module)) print load_fiche_titre($langs->trans("ObjectProperties"), '', ''); - + print ''."\n"; print '
'; print ''; print ''; @@ -2470,16 +2487,22 @@ elseif (! empty($module)) print ''; - print ''; print ''; print ''; print ''; print ''; + print ''; print ''; print ''; print ''; - print ''; + print ''; print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; print ''; print ''; print ''; @@ -2500,11 +2523,17 @@ elseif (! empty($module)) print ''; print ''; print ''; + print ''; print ''; print ''; print ''; - print ''; + print ''; print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; print ''; print ''; @@ -2548,7 +2583,7 @@ elseif (! empty($module)) print ''; - print ''; print ''; + print ''; print ''; @@ -2575,16 +2613,34 @@ elseif (! empty($module)) print $propvisible?$propvisible:''; print ''; print ''; print ''; + print ''; + print ''; + print ''; + print ''; + /*print '';*/ print ''; print ''; print ''; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 43488429807..7d3de98e4df 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -68,21 +68,21 @@ class MyObject extends CommonObject * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" * 'label' the translation key. * 'enabled' is a condition when the field must be managed. + * 'position' is the sort order of field. + * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). Using a negative value means field is not shown by default on list but can be selected for viewing) * 'noteditable' says if field is not editable (1 or 0) - * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. * 'index' if we want an index in database. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). - * 'position' is the sort order of field. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). * 'css' is the CSS style to use on field. For example: 'maxwidth200' * 'help' is a string visible as a tooltip on field - * 'comment' is not used. You can store here any text of your choice. It is not used by application. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record - * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. + * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") + * 'comment' is not used. You can store here any text of your choice. It is not used by application. */ // BEGIN MODULEBUILDER PROPERTIES @@ -91,13 +91,13 @@ class MyObject extends CommonObject */ public $fields=array( 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), - 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'notnull'=> 1, 'default'=>'(PROV)', 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), + 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'default'=>'', 'notnull'=> 1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>20), 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text', 'showoncombobox'=>1), 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for amount'), 'qty' =>array('type'=>'real', 'label'=>'Qty', 'enabled'=>1, 'visible'=>1, 'default'=>'0', 'position'=>45, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for quantity', 'css'=>'maxwidth75imp'), 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php:1', 'label'=>'ThirdParty', 'visible'=> 1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'help'=>'LinkToThirparty'), - 'fk_project' =>array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>1, 'visible'=>-1, 'position'=>52, 'notnull'=>-1, 'index'=>1,), + 'fk_project' =>array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>1, 'visible'=>-1, 'position'=>52, 'notnull'=>-1, 'index'=>1), 'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>60), 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61), 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62), diff --git a/htdocs/modulebuilder/template/core/modules/myobject/doc/doc_generic_myobject_odt.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php similarity index 100% rename from htdocs/modulebuilder/template/core/modules/myobject/doc/doc_generic_myobject_odt.modules.php rename to htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php diff --git a/htdocs/modulebuilder/template/core/modules/myobject/mod_myobject_advanced.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php similarity index 100% rename from htdocs/modulebuilder/template/core/modules/myobject/mod_myobject_advanced.php rename to htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php diff --git a/htdocs/modulebuilder/template/core/modules/myobject/mod_myobject_standard.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php similarity index 100% rename from htdocs/modulebuilder/template/core/modules/myobject/mod_myobject_standard.php rename to htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php diff --git a/htdocs/modulebuilder/template/core/modules/myobject/modules_myobject.php b/htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php similarity index 100% rename from htdocs/modulebuilder/template/core/modules/myobject/modules_myobject.php rename to htdocs/modulebuilder/template/core/modules/mymodule/modules_myobject.php diff --git a/htdocs/modulebuilder/template/core/tpl/linkedobjectblock_myobject.tpl.php b/htdocs/modulebuilder/template/core/tpl/linkedobjectblock_myobject.tpl.php new file mode 100644 index 00000000000..c0b2e073ad0 --- /dev/null +++ b/htdocs/modulebuilder/template/core/tpl/linkedobjectblock_myobject.tpl.php @@ -0,0 +1,58 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Protection to avoid direct call of template +if (empty($conf) || ! is_object($conf)) +{ + print "Error, template page can't be called as URL"; + exit; +} + + +print "\n"; + + +global $user; +global $noMoreLinkedObjectBlockAfter; + +$langs = $GLOBALS['langs']; +$linkedObjectBlock = $GLOBALS['linkedObjectBlock']; + +// Load translation files required by the page +$langs->load("mymodule"); + +$total=0; $ilink=0; +foreach($linkedObjectBlock as $key => $objectlink) +{ + $ilink++; + + $trclass='oddeven'; + if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total'; + ?> + + + + + + + + + + \n"; diff --git a/htdocs/modulebuilder/template/core/tpl/mytemplate.tpl.php b/htdocs/modulebuilder/template/core/tpl/mytemplate.tpl.php deleted file mode 100644 index 8e871e7f416..00000000000 --- a/htdocs/modulebuilder/template/core/tpl/mytemplate.tpl.php +++ /dev/null @@ -1,35 +0,0 @@ -. - */ - -/** - * \file core/tpl/mytemplate.tpl.php - * \ingroup mymodule - * \brief Example template. - * - * Put detailed description here. - */ - -// Protection to avoid direct call of template -if (empty($conf) || ! is_object($conf)) -{ - print "Error, template page can't be called as URL"; - exit; -} - - -/** Your code here. */ -echo "Hello world!";
'; print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey")); print ''.$langs->trans("Type").''; + print ''.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelp")).''.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).''.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).''.$langs->trans("DefaultValue").''.$langs->trans("DatabaseIndex").''.$langs->trans("ForeignKey").''.$langs->trans("Position").''.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).''.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).''.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).''.$langs->trans("NotEditable").''.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).''.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).''.$langs->trans("CSSClass").''.$langs->trans("KeyForTooltip").''.$langs->trans("ShowOnCombobox").''.$langs->trans("Disabled").''.$langs->trans("Comment").'
'; print ''; @@ -2531,13 +2560,19 @@ elseif (! empty($module)) $proptype=$propval['type']; $proparrayofkeyval=$propval['arrayofkeyval']; $propnotnull=$propval['notnull']; - $propsearchall=$propval['searchall']; $propdefault=$propval['default']; $propindex=$propval['index']; + $propforeignkey=$propval['foreignkey']; $propposition=$propval['position']; $propenabled=$propval['enabled']; $propvisible=$propval['visible']; + $propnoteditable=$propval['noteditable']; + $propsearchall=$propval['searchall']; $propisameasure=$propval['isameasure']; + $propcss=$propval['css']; + $prophelp=$propval['help']; + $propshowoncombobox=$propval['showoncombobox']; + //$propdisabled=$propval['disabled']; $propcomment=$propval['comment']; print '
'; print $proplabel; print ''; + print ''; print $proptype; print ''; @@ -2565,6 +2600,9 @@ elseif (! empty($module)) print ''; print $propindex?'1':''; print ''; + print $propforeignkey?$propforeignkey:''; + print ''; print $propposition; print ''; - print $propisameasure?$propisameasure:''; + print $propnoteditable?$propnoteditable:''; print ''; print $propsearchall?'1':''; print ''; + print $propisameasure?$propisameasure:''; + print ''; + print $propcss?$propcss:''; + print ''; + print $prophelp?$prophelp:''; + print ''; + print $propshowoncombobox?$propshowoncombobox:''; + print ''; + print $propdisabled?$propdisabled:''; + print ''; print $propcomment; print ''; - print ''.img_delete().''; + if ($propname != 'rowid') + { + print ''.img_delete().''; + } print '
trans("MyObject"); ?>getNomUrl(1); ?>date, 'day'); ?>getLibStatut(7); ?>'.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink'); ?>