From ceeb9d7f1b93046d84d6477a84b4ffad08eff68b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 11 Jul 2017 20:47:49 +0200 Subject: [PATCH] Debug modulebuilder --- htdocs/langs/en_US/modulebuilder.lang | 2 + htdocs/modulebuilder/index.php | 231 +++++++++++++----- .../template/class/myobject.class.php | 20 +- .../modulebuilder/template/myobject_list.php | 24 +- 4 files changed, 198 insertions(+), 79 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 8fab0a7b07f..5a3470aebce 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -38,3 +38,5 @@ 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 +SpecificationFile=File with business rules +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. \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 2547b893055..a1c30b7c94a 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -37,9 +37,10 @@ $cancel=GETPOST('cancel','alpha'); $module=GETPOST('module','alpha'); $tab=GETPOST('tab','aZ09'); $tabobj=GETPOST('tabobj','alpha'); +$propertykey=GETPOST('propertykey','alpha'); if (empty($module)) $module='initmodule'; if (empty($tab)) $tab='description'; -if (empty($tabobj)) $tabobj='newobject'; +if (empty($tabobj)) $tabobj='newobjectifnoobj'; $file=GETPOST('file','alpha'); $modulename=dol_sanitizeFileName(GETPOST('modulename','alpha')); @@ -58,6 +59,7 @@ $FILEFLAG='modulebuilder.txt'; $now=dol_now(); + /* * Actions */ @@ -320,6 +322,29 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) $tabobj = 'deleteobject'; } +if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) +{ + if (! $error) + { + $modulelowercase=strtolower($module); + $objectlowercase=strtolower($objectname); + + // File of class + $fileforclass = $dirins.'/'.$modulelowercase.'/class/'.$objectlowercase.'.class.php'; + + // TODO + + // File of sql + $fileforsql = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.sql'; + $fileforsqlkey = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.key.sql'; + + + // TODO + } +} + + + if ($dirins && $action == 'generatepackage') { $modulelowercase=strtolower($module); @@ -838,9 +863,11 @@ elseif (! empty($module)) $h++; $listofobject = dol_dir_list($dir, 'files', 0, '\.txt$'); + $firstobjectname=''; foreach($listofobject as $fileobj) { $objectname = preg_replace('/\.txt$/', '', $fileobj['name']); + if (empty($firstobjectname)) $firstobjectname = $objectname; $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.'&tabobj='.$objectname; $head3[$h][1] = $objectname; @@ -853,6 +880,12 @@ elseif (! empty($module)) $head3[$h][2] = 'deleteobject'; $h++; + // If tabobj was not defined, then we check if there is one obj. If yes, we force on it, if no, we will show tab to create new objects. + if ($tabobj == 'newobjectifnoobj') + { + if ($firstobjectname) $tabobj=$firstobjectname; + else $tabobj = 'newobject'; + } dol_fiche_head($head3, $tabobj, '', -1, ''); @@ -888,92 +921,168 @@ elseif (! empty($module)) } else { - try { - $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php'; - $pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php'; - $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.class.php'; - $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.class.php'; - print ' '.$langs->trans("ClassFile").' : '.$pathtoclass.'
'; - print ' '.$langs->trans("ApiClassFile").' : '.$pathtoapi.'
'; - print ' '.$langs->trans("PageForList").' : '.$pathtolist.'
'; - print ' '.$langs->trans("PageForCreateEditView").' : '.$pathtocard.'
'; + if ($action == 'deleteproperty') + { + $formconfirm = $form->formconfirm( + $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey','alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj), + $langs->trans('Delete'), $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey','alpha')), 'confirm_deleteproperty', '', 0, 1 + ); - $result = dol_include_once($pathtoclass); - $tmpobjet = new $tabobj($db); + // Print form confirm + print $formconfirm; + } - $reflector = new ReflectionClass($tabobj); - $properties = $reflector->getProperties(); // Can also use get_object_vars - $propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars - //$propstat = $reflector->getStaticProperties(); + if ($action != 'editfile' || empty($file)) + { + try { + $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php'; + $pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php'; + $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php'; + $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php'; + print ' '.$langs->trans("ClassFile").' : '.$pathtoclass.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + print ' '.$langs->trans("ApiClassFile").' : '.$pathtoapi.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + print ' '.$langs->trans("PageForList").' : '.$pathtolist.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; + print ' '.$langs->trans("PageForCreateEditView").' : '.$pathtocard.''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print '
'; - print load_fiche_titre($langs->trans("Properties"), '', ''); + $result = dol_include_once($pathtoclass); + $tmpobjet = new $tabobj($db); - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + $reflector = new ReflectionClass($tabobj); + $properties = $reflector->getProperties(); // Can also use get_object_vars + $propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars + //$propstat = $reflector->getStaticProperties(); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - foreach($properties as $propkey => $propval) - { - if ($propval->class == $tabobj) + print load_fiche_titre($langs->trans("Properties"), '', ''); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Property"); - print ' ('.$langs->trans("Example").')'; - print ''.$langs->trans("Comment").''.$langs->trans("Type").''.$langs->trans("DefaultValue").'
'; - print ''; - print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $properties = $tmpobjet->fields; + + foreach($properties as $propkey => $propval) { - $propname=$propval->getName(); + /* If from Reflection + if ($propval->class == $tabobj) + { + $propname=$propval->getName(); + $comment=$propval->getDocComment(); + $type=gettype($tmpobjet->$propname); + $default=$propdefault[$propname]; + // Discard generic properties + if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue; - // Discard generic properties - if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue; + // Keep or not lines + if (in_array($propname, array('fk_element', 'lines'))) continue; + }*/ - // Keep or not lines - if (in_array($propname, array('fk_element', 'lines'))) continue; + $propname=$propkey; + $proplabel=$propval['label']; + $proptype=$propval['type']; + $propposition=$propval['position']; + $propdefault=$propval['default']; + $propindex=$propval['index']; + $propcomment=$propval['comment']; + print ''; - print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; } + print '
'.$langs->trans("Property"); + print ' ('.$langs->trans("Example").')'; + print ''.$langs->trans("Label").''.$langs->trans("Type").''.$langs->trans("Position").''.$langs->trans("DefaultValue").''.$langs->trans("Index").''.$langs->trans("Comment").'
'; + print ''; + print '
'; + print ''; print $propname; print ''; - print $propval->getDocComment(); + print $proplabel; print ''; - print gettype($tmpobjet->$propname); + print $proptype; print ''; - print $propdefault[$propname]; + print $propposition; print ''; - + print $propdefault; print ''; + print yn($propindex); + print ''; + print $propcomment; + print ''; + print ''.img_delete().''; + print '
'; + + print '
'; } - print ''; + catch(Exception $e) + { + print $e->getMessage(); + } + } + else + { + $fullpathoffile=dol_buildpath($file, 0); + + $content = file_get_contents($fullpathoffile); + + // New module + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + $doleditor=new DolEditor('editfilecontent', $content, '', '600', 'Full', 'In', true, false, false, 0, '99%'); + print $doleditor->Create(1, '', false); + print '
'; + print '
'; + print ''; + print '   '; + print ''; + print '
'; print '
'; } - catch(Exception $e) - { - print $e->getMessage(); - } } } diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 9ef593367c9..4c85a6e5a86 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -52,22 +52,24 @@ class MyObject extends CommonObject * @var array Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe */ protected $ismultientitymanaged = 1; - - /** - * @var string String with name of icon for myobject - */ + * @var string String with name of icon for myobject + */ public $picto = 'myobject'; - /** - * @var int Entity Id - */ - public $entity; + /* BEGIN PROPERTY FIELDS - Do not remove this comment */ /** * @var array Array with all fields and their property */ - public $fields; + public $fields=array( + 'ref'=>array('type'=>'string','label'=>'Ref','position'=>10,'index'=>true,'comment'=>'Reference of object'), + 'entity'=>array('type'=>'integer','label'=>'Entity','index'=>true), + 'status'=>array('type'=>'integer','label'=>'Status','index'=>true), + 'date'=>array('type'=>'date','label'=>'Date','default'=>'__NOW__'), + 'title'=>array('type'=>'string','label'=>'Title'), + ); + /* END PROPERTY FIELDS - Do not remove this comment */ diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 28624dc9fc2..7e67c04ecc2 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -68,13 +68,7 @@ $toselect = GETPOST('toselect', 'array'); $id = GETPOST('id','int'); $backtopage = GETPOST('backtopage'); -$myparam = GETPOST('myparam','alpha'); - -$search_all=trim(GETPOST("sall")); -$search_field1=GETPOST("search_field1"); -$search_field2=GETPOST("search_field2"); -$search_myfield=GETPOST('search_myfield'); -$optioncss = GETPOST('optioncss','alpha'); +$optioncss = GETPOST('optioncss','alpha'); // Load variable for pagination $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; @@ -85,6 +79,7 @@ if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; + if (! $sortfield) $sortfield="t.rowid"; // Set here default search field if (! $sortorder) $sortorder="ASC"; @@ -96,6 +91,19 @@ if ($user->societe_id > 0) //accessforbidden(); } +// Initialize array of search criterias +$object=new MyModule($db); +$search_all=trim(GETPOST("search_all")); +$search=array(); +foreach($object->fields as $key) +{ + if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); +} +/*$search_field1=GETPOST("search_field1"); +$search_field2=GETPOST("search_field2"); +$search_myfield=GETPOST('search_myfield'); +*/ + // Initialize technical object to manage context to save list fields $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectlist'; @@ -133,8 +141,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab } -$object=new Skeleton_Class($db); -