From 69b26dcb4ebea5a36cd6dcfb9fbf4ced48a910de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Jun 2017 21:23:52 +0200 Subject: [PATCH] Work on modulebuilder --- htdocs/langs/en_US/modulebuilder.lang | 10 +- htdocs/modulebuilder/index.php | 152 ++++++++++++++++-- .../template/class/myobject.class.php | 22 ++- 3 files changed, 159 insertions(+), 25 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index b8300182b05..8d9a31cfdf7 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -17,7 +17,7 @@ ModuleBuilderDescpermissions=This tab is dedicated to define the new permissions 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 with your IDE. ModuleBuilderDeschooks=This tab is dedicated to hooks. ModuleBuilderDescwidgets=This tab is dedicated to manage/build widgets. -ModuleBuilderDescbuildpackage=You can generate here a "ready to distribute" package file (a normalized .zip file) of your module. Just click on button to get your module package file. +ModuleBuilderDescbuildpackage=You can generate here a "ready to distribute" package file (a normalized .zip file) of your module. Just click on button to build the module package file. ModuleBuilderDescdangerzone=You can delete your module. WARNING: All files of module will be definetly lost ! DangerZone=Danger zone BuildPackage=Build package @@ -25,4 +25,10 @@ ModuleIsNotActive=This module was not activated yet (go into Home-Setup-Module t ModuleIsLive=This module has been activated. Any change on it may break a current active feature. DescriptionLong=Long description EditorName=Name of editor -EditorUrl=URL of editor \ No newline at end of file +EditorUrl=URL of editor +DescriptorFile=Descriptor file of module +ClassFile=File for PHP class +ApiClassFile=File for PHP API class +PageForList=PHP page for list of record +PageForCreateEditView=PHP page to create/edit/view a record +PathToModulePackage=Path to zip of module/application package \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 0f60d76ca4f..d9ae491b654 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -454,7 +454,9 @@ elseif (! empty($module)) $head2 = array(); $h=0; - $modulestatusinfo=img_info('').' '.$langs->trans("ModuleIsNotActive"); + $modulelowercase=strtolower($module); + + $modulestatusinfo=img_info('').' '.$langs->trans("ModuleIsNotActive"); if (! empty($conf->$module->enabled)) { $modulestatusinfo=img_warning().' '.$langs->trans("ModuleIsLive"); @@ -513,7 +515,12 @@ elseif (! empty($module)) if ($tab == 'description') { - print '
'; + $pathtofile = $modulelowercase.'/core/modules/mod'.$module.'.class.php'; + + print ' '.$langs->trans("DescriptorFile").' : '.$pathtofile.'
'; + print '
'; + + print '
'; print '
'; print ''; @@ -579,12 +586,9 @@ elseif (! empty($module)) if ($tab == 'objects') { - $head3 = array(); $h=0; - $modulelowercase=strtolower($module); - // Dir for module $dir = $dirins.'/'.$modulelowercase.'/class'; @@ -621,10 +625,92 @@ elseif (! empty($module)) print ''; print ''; } - - if ($tabobj == 'fields') + else { - print $langs->trans("FeatureNotYetAvailable").'

'; + 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.'
'; + + $result = dol_include_once($pathtoclass); + $tmpobjet = new $tabobj($db); + + $reflector = new ReflectionClass($tabobj); + $properties = $reflector->getProperties(); + $propdefault = $reflector->getDefaultProperties(); + + print load_fiche_titre($langs->trans("Properties"), '', ''); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + foreach($properties as $propkey => $propval) + { + if ($propval->class == $tabobj) + { + $propname=$propval->getName(); + + // Discard generic properties + if (in_array($propname, array('element', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue; + + // Keep or not lines + if (in_array($propname, array('fk_element', 'lines'))) continue; + + + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + } + } + print '
'.$langs->trans("Property").''.$langs->trans("Description").''.$langs->trans("Type").''.$langs->trans("DefaultValue").'
'; + print ''; + print '
'; + print $propname; + print ''; + + print ''; + + print ''; + print $propdefault[$propname]; + print ''; + + print '
'; + + print ''; + } + catch(Exception $e) + { + print $e->getMessage(); + } } } @@ -666,10 +752,9 @@ elseif (! empty($module)) $var=True; foreach ($triggers as $trigger) { - print ''; print ''.$trigger['picto'].''; - print ''.$trigger['file'].''; + print ''.$trigger['relpath'].''; print ''.$trigger['status'].''; print ''; $text=$trigger['info']; @@ -698,11 +783,56 @@ elseif (! empty($module)) print '
'; } + $modulelowercase=strtolower($module); + + // Zip file to build + $FILENAMEZIP=''; + + // Load module + dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php'); + $class='mod'.$module; + + if (class_exists($class)) + { + try { + $moduleobj = new $class($db); + } + catch(Exception $e) + { + $error++; + dol_print_error($e->getMessage()); + } + } + else + { + $error++; + $langs->load("errors"); + dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module)); + exit; + } + + $arrayversion=explode('.',$moduleobj->version,3); + if (count($arrayversion)) + { + $FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip"; + $outputfile = $conf->admin->dir_temp.'/'.$FILENAMEZIP; + } + + print ' '. $langs->trans("PathToModulePackage") . ' : '; + if (! dol_is_file($outputfile)) print ''.$langs->trans("PackageFileNotYetGenerated").''; + else { + print ''.$outputfile.''; + print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfile), 'dayhour').')'; + } + 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 9e66b9410f6..4993f60f83c 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -21,8 +21,8 @@ /** * \file htdocs/modulebuilder/template/class/myobject.class.php - * \ingroup mymodule othermodule1 othermodule2 - * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) + * \ingroup mymodule + * \brief This file is a CRUD class file for MyObject (Create/Read/Update/Delete) */ // Put here all includes required by your class file @@ -31,24 +31,22 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; /** - * Class MyObject - * - * Put here description of your class. + * Class for MyObject */ class MyObject extends CommonObject { /** * @var string Id to identify managed object */ - public $element = 'mymoduleobject'; + public $element = 'myobject'; /** * @var string Name of table without prefix where object is stored */ - public $table_element = 'mymoduleobject'; + public $table_element = 'myobject'; /** * @var array Array with all fields and their property */ - public $picto = 'generic'; + public $picto = 'myobject'; /** * @var array Array with all fields and their property */ @@ -67,12 +65,12 @@ class MyObject extends CommonObject protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe - public $table_element_line = 'mymoduleobjectdet'; - public $class_element_line = 'MyModuleObjectline'; - public $fk_element = 'fk_mymoduleobject'; + public $table_element_line = 'myobjectdet'; + public $class_element_line = 'MyObjectline'; + public $fk_element = 'fk_myobject'; /** - * @var MyModuleObjectLine[] Lines + * @var MyObjectLine[] Lines */ public $lines = array();