From 926683763ba8cc9d796872139b4910500873a79e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Jan 2018 17:38:15 +0100 Subject: [PATCH] Modulebuilde fix sort of fields, fix generation of files --- htdocs/core/class/html.form.class.php | 1 + htdocs/core/lib/modulebuilder.lib.php | 2 + htdocs/langs/en_US/modulebuilder.lang | 2 + htdocs/modulebuilder/index.php | 76 +++++++++++++++---- .../modulebuilder/template/myobject_list.php | 2 +- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8230786c449..d20db100014 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5723,6 +5723,7 @@ class Form $lis=''; $listcheckedstring=''; + $array = dol_sort_array($array, 'position'); foreach($array as $key => $val) { /* var_dump($val); diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index d14a60ab94f..8e2cba43097 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -35,6 +35,7 @@ * @param string $addfieldentry Array of the field entry to add array('key'=>,'type'=>,''label'=>,'visible'=>,'enabled'=>,'position'=>,'notnull'=>','index'=>,'searchall'=>,'comment'=>,'help'=>,'isameasure') * @param string $delfieldentry Id of field to remove * @return int|object <=0 if KO, Object if OK + * @see rebuildObjectSql */ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array() ,$delfieldentry='') { @@ -202,6 +203,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir=' * @param string $readdir Directory source (use $destdir when not defined) * @param Object $object If object was already loaded/known, it is pass to avaoid another include and new. * @return int <=0 if KO, >0 if OK + * @see rebuildObjectClass */ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $object=null) { diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 78d6092f006..9e30ee6f1de 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -43,6 +43,8 @@ PathToModulePackage=Path to zip of module/application package PathToModuleDocumentation=Path to file of module/application documentation SpaceOrSpecialCharAreNotAllowed=Spaces or special characters are not allowed. FileNotYetGenerated=File not yet generated +RegenerateClassAndSql=Erase and regenerate class and sql files +RegenerateMissingFiles=Generate missing files SpecificationFile=File with business rules LanguageFile=File for language ConfirmDeleteProperty=Are you sure you want to delete the property %s ? This will change code in PHP class but also remove column from table definition of object. diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index a915728903c..3b2e36e21d8 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -419,22 +419,53 @@ if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj)) { + $error = 0; + $objectname = $tabobj; $srcdir = $dirread.'/'.strtolower($module); $destdir = $dirins.'/'.strtolower($module); dol_mkdir($destdir); - $addfieldentry = array( - 'name'=>GETPOST('propname','aZ09'),'label'=>GETPOST('proplabel','alpha'),'type'=>GETPOST('proptype','alpha'), - 'arrayofkeyval'=>GETPOST('proparrayofkeyval','none'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}' - 'visible'=>GETPOST('propvisible','int'),'enabled'=>GETPOST('propenabled','int'), - 'position'=>GETPOST('propposition','int'),'notnull'=>GETPOST('propnotnull','int'),'index'=>GETPOST('propindex','int'),'searchall'=>GETPOST('propsearchall','int'), - 'isameasure'=>GETPOST('propisameasure','int'), 'comment'=>GETPOST('propcomment','alpha'),'help'=>GETPOST('prophelp','alpha')); - - if (! empty($addfieldentry['arrayofkeyval']) && ! is_array($addfieldentry['arrayofkeyval'])) + // We click on add property + if (! GETPOST('regenerateclasssql') && ! GETPOST('regeneratemissing')) { - $addfieldentry['arrayofkeyval'] = dol_json_decode($addfieldentry['arrayofkeyval'], true); + if (! GETPOST('propname','aZ09')) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors'); + } + if (! GETPOST('proplabel','alpha')) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); + } + if (! GETPOST('proptype','alpha')) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); + } + + if (! $error) + { + $addfieldentry = array( + 'name'=>GETPOST('propname','aZ09'),'label'=>GETPOST('proplabel','alpha'),'type'=>GETPOST('proptype','alpha'), + 'arrayofkeyval'=>GETPOST('proparrayofkeyval','none'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}' + 'visible'=>GETPOST('propvisible','int'),'enabled'=>GETPOST('propenabled','int'), + 'position'=>GETPOST('propposition','int'),'notnull'=>GETPOST('propnotnull','int'),'index'=>GETPOST('propindex','int'),'searchall'=>GETPOST('propsearchall','int'), + 'isameasure'=>GETPOST('propisameasure','int'), 'comment'=>GETPOST('propcomment','alpha'),'help'=>GETPOST('prophelp','alpha')); + + if (! empty($addfieldentry['arrayofkeyval']) && ! is_array($addfieldentry['arrayofkeyval'])) + { + $addfieldentry['arrayofkeyval'] = dol_json_decode($addfieldentry['arrayofkeyval'], true); + } + } + } + + if (GETPOST('regeneratemissing')) + { + setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings'); + $error++; } // Edit the class file to write properties @@ -1431,6 +1462,7 @@ elseif (! empty($module)) $pathtosqlkey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.key.sql'; $pathtolib = strtolower($module).'/lib/'.strtolower($tabobj).'.lib.php'; $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png'; + $pathtoscript = strtolower($module).'/scripts/'.strtolower($tabobj).'.php'; $realpathtoclass = dol_buildpath($pathtoclass, 0, 1); $realpathtoapi = dol_buildpath($pathtoapi, 0, 1); @@ -1445,6 +1477,7 @@ elseif (! empty($module)) $realpathtosqlkey = dol_buildpath($pathtosqlkey, 0, 1); $realpathtolib = dol_buildpath($pathtolib, 0, 1); $realpathtopicto = dol_buildpath($pathtopicto, 0, 1); + $realpathtoscript = dol_buildpath($pathtoscript, 0, 1); print '
'; print ' '.$langs->trans("ClassFile").' : '.($realpathtoclass?'':'').$pathtoclass.($realpathtoclass?'':'').''; @@ -1506,6 +1539,11 @@ elseif (! empty($module)) print ' '.img_picto($langs->trans("Edit"), 'edit').''; print '
'; + print '
'; + print ' '.$langs->trans("ScriptFile").' : '.($realpathtoscript?'':'').$pathtoscript.($realpathtoscript?'':'').''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + print '
'; print '
'; @@ -1539,9 +1577,15 @@ elseif (! empty($module)) //$propstat = $reflector->getStaticProperties(); //var_dump($reflectorpropdefault); + print '
'; + + print ''; + print ''; + print '

'; + + print load_fiche_titre($langs->trans("Properties"), '', ''); - print ''; print ''; print ''; @@ -1581,19 +1625,19 @@ elseif (! empty($module)) { // Line to add a property print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 7d0c5a7d26c..96c9967880c 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -124,7 +124,7 @@ $arrayfields=array(); foreach($object->fields as $key => $val) { // 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']); + if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']); } // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))