From 6cd6de092da19e83faf5e7b78c28afe991178d73 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Jan 2020 11:04:13 +0100 Subject: [PATCH 1/5] Fix modulebuilder --- .../template/core/modules/modMyModule.class.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 79482128362..c079fd4cf93 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -334,13 +334,14 @@ class modMyModule extends DolibarrModules $this->export_code[$r]=$this->rights_class.'_'.$r; $this->export_label[$r]='MyObjectLines'; // Translation key (used only if key ExportDataset_xxx_z not found) $this->export_icon[$r]='myobject@mymodule'; - $keyforclass = 'MyObject'; $keyforclassfile='/mymobule/class/myobject.class.php'; $keyforelement='myobject'; + // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array + $keyforclass = 'MyObject'; $keyforclassfile='/mymobule/class/myobject.class.php'; $keyforelement='myobject@mymodule'; include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php'; - //$keyforclass = 'MyObjectLine'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobjectline'; $keyforalias='tl'; + //$keyforclass = 'MyObjectLine'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobjectline@mymodule'; $keyforalias='tl'; //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php'; - $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject'; + $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule'; include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; - //$keyforselect='myobjectline'; $keyforaliasextra='extraline'; $keyforelement='myobjectline'; + //$keyforselect='myobjectline'; $keyforaliasextra='extraline'; $keyforelement='myobjectline@mymodule'; //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; //$this->export_dependencies_array[$r] = array('myobjectline'=>array('tl.rowid','tl.ref')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields) //$this->export_special_array[$r] = array('t.field'=>'...'); @@ -362,9 +363,9 @@ class modMyModule extends DolibarrModules $this->export_code[$r]=$this->rights_class.'_'.$r; $this->export_label[$r]='MyObjectLines'; // Translation key (used only if key ExportDataset_xxx_z not found) $this->export_icon[$r]='myobject@mymodule'; - $keyforclass = 'MyObject'; $keyforclassfile='/mymobule/class/myobject.class.php'; $keyforelement='myobject'; + $keyforclass = 'MyObject'; $keyforclassfile='/mymobule/class/myobject.class.php'; $keyforelement='myobject@mymodule'; include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php'; - $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject'; + $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule'; include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; //$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields) $this->export_sql_start[$r]='SELECT DISTINCT '; From 6602a7046e0ace02f029034d0aabbd0f32e04826 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Jan 2020 11:17:56 +0100 Subject: [PATCH 2/5] Doc --- .../modulebuilder/template/core/modules/modMyModule.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index c079fd4cf93..e51eeb51921 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -337,6 +337,8 @@ class modMyModule extends DolibarrModules // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array $keyforclass = 'MyObject'; $keyforclassfile='/mymobule/class/myobject.class.php'; $keyforelement='myobject@mymodule'; include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php'; + //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text'; + //unset($this->export_fields_array[$r]['t.fieldtoremove']); //$keyforclass = 'MyObjectLine'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobjectline@mymodule'; $keyforalias='tl'; //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php'; $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule'; From 9729b3a1c7d70d6ec4e6f4a3a00e72e23ce91d0f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Jan 2020 12:39:47 +0100 Subject: [PATCH 3/5] Fix modulebuilder template --- .../template/class/myobject.class.php | 58 +++++++++++++++++++ .../mymodule/mod_myobject_advanced.php | 3 +- .../mymodule/mod_myobject_standard.php | 3 +- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 4859162abb0..7bbd396e637 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -898,6 +898,64 @@ class MyObject extends CommonObject } } + /** + * Returns the reference to the following non used object depending on the active numbering module. + * + * @return string Object free reference + */ + public function getNextNumRef() + { + global $langs, $conf; + $langs->load("mymodule@myobject"); + + if (empty($conf->global->MYMODULE_MYOBJECT_ADDON)) { + $conf->global->MYMODULE_MYOBJECT_ADDON = 'mod_mymobject_standard'; + } + + if (!empty($conf->global->MYMODULE_MYOBJECT_ADDON)) + { + $mybool = false; + + $file = $conf->global->MYMODULE_MYOBJECT_ADDON.".php"; + $classname = $conf->global->MYMODULE_MYOBJECT_ADDON; + + // Include file with class + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) + { + $dir = dol_buildpath($reldir."core/modules/mymodule/"); + + // Load file with numbering class (if found) + $mybool |= @include_once $dir.$file; + } + + if ($mybool === false) + { + dol_print_error('', "Failed to include file ".$file); + return ''; + } + + $obj = new $classname(); + $numref = $obj->getNextValue($this); + + if ($numref != "") + { + return $numref; + } + else + { + $this->error = $obj->error; + //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); + return ""; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_MYMODULE_MYOBJECT_ADDON_NotDefined"); + return ""; + } + } + /** * Create a document onto disk according to template module. * diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php index 6a3a274f443..26866a6b9f1 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php @@ -118,11 +118,10 @@ class mod_myobject_advanced extends ModeleNumRefMyObject /** * Return next free value * - * @param Product $objprod Object product * @param Object $object Object we need next value for * @return string Value if KO, <0 if KO */ - public function getNextValue($objprod, $object) + public function getNextValue($object) { global $db,$conf; diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php index f9a786dfe55..e18e7636b6d 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_standard.php @@ -109,11 +109,10 @@ class mod_myobject_standard extends ModeleNumRefMyObject /** * Return next free value * - * @param Product $objprod Object product * @param Object $object Object we need next value for * @return string Value if KO, <0 if KO */ - public function getNextValue($objprod, $object) + public function getNextValue($object) { global $db,$conf; From d80764a1791f147cf20b2f079b23b593ea5bebb8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Jan 2020 12:39:05 +0100 Subject: [PATCH 4/5] Fix column not visible after switching column when visibility=3 --- htdocs/core/tpl/commonfields_view.tpl.php | 4 +++- htdocs/modulebuilder/template/myobject_card.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/commonfields_view.tpl.php b/htdocs/core/tpl/commonfields_view.tpl.php index 2eae2655fbb..7971a8dc85c 100644 --- a/htdocs/core/tpl/commonfields_view.tpl.php +++ b/htdocs/core/tpl/commonfields_view.tpl.php @@ -84,7 +84,9 @@ foreach ($object->fields as $key => $val) continue; } - if (abs($val['visible']) != 1) continue; // Discard such field from form + // Discard if extrafield is a hidden field on form + if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4) continue; + if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) continue; // We don't want this field if (in_array($key, array('ref', 'status'))) continue; // Ref and status are already in dol_banner diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 7b4a2abc50d..2d28495cdc3 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -371,7 +371,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''."\n"; // Common attributes - //$keyforbreak='fieldkeytoswitchonsecondcolumn'; + //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just after this field //unset($object->fields['fk_project']); // Hide field already shown in banner //unset($object->fields['fk_soc']); // Hide field already shown in banner include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; From 750fa83e9628964634ab6af26904e260591b263b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Jan 2020 13:48:44 +0100 Subject: [PATCH 5/5] FIX Bad management of elementtype not llx_actioncomm --- htdocs/core/lib/company.lib.php | 10 +++- htdocs/core/lib/functions2.lib.php | 50 +++++++++++-------- .../modulebuilder/template/myobject_card.php | 2 +- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 83876b63be9..8f658d850fe 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1335,6 +1335,8 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", o.ref"; elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') $sql .= ", o.ref"; elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') $sql .= ", o.ref"; + elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && is_array($filterobj->fields['ref']) && $filterobj->table_element && $filterobj->element) $sql .= ", o.ref"; + $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id"; @@ -1359,6 +1361,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", ".MAIN_DB_PREFIX."ticket as o"; elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o"; elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') $sql .= ", ".MAIN_DB_PREFIX."contrat as o"; + elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && is_array($filterobj->fields['ref']) && $filterobj->table_element && $filterobj->element) $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o"; $sql .= " WHERE a.entity IN (".getEntity('agenda').")"; if ($force_filter_contact === false) { @@ -1394,6 +1397,11 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'"; if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id; } + elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && is_array($filterobj->fields['ref']) && $filterobj->table_element && $filterobj->element) + { + $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element)."'"; + if ($filterobj->id) $sql .= " AND a.fk_element = ".$filterobj->id; + } } // Condition on actioncode @@ -1712,7 +1720,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin // Title of event //$out.=''; - // Objet lie + // Linked object $out .= '
'.dol_trunc($histo[$key]['note'], 40).''; if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) { diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index cc6fb31c1de..e1603fce57d 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1797,7 +1797,7 @@ function getSoapParams() * Return link url to an object * * @param int $objectid Id of record - * @param string $objecttype Type of object ('invoice', 'order', 'expedition_bon', ...) + * @param string $objecttype Type of object ('invoice', 'order', 'expedition_bon', 'myobject@mymodule', ...) * @param int $withpicto Picto to show * @param string $option More options * @return string URL of link to object id/type @@ -1807,28 +1807,35 @@ function dolGetElementUrl($objectid, $objecttype, $withpicto = 0, $option = '') global $db, $conf, $langs; $ret = ''; + $regs = array(); - // Parse element/subelement (ex: project_task) - $module = $element = $subelement = $objecttype; + // If we ask an resource form external module (instead of default path) + if (preg_match('/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) { + $myobject = $regs[1]; + $module = $regs[2]; + } + + // Parse $objecttype (ex: project_task) + $module = $myobject = $objecttype; if (preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs)) { - $module = $element = $regs[1]; - $subelement = $regs[2]; + $module = $regs[1]; + $myobject = $regs[2]; } // Generic case for $classpath - $classpath = $element.'/class'; + $classpath = $module.'/class'; // Special cases, to work with non standard path if ($objecttype == 'facture' || $objecttype == 'invoice') { $classpath = 'compta/facture/class'; $module='facture'; - $subelement='facture'; + $myobject='facture'; } elseif ($objecttype == 'commande' || $objecttype == 'order') { $classpath = 'commande/class'; $module='commande'; - $subelement='commande'; + $myobject='commande'; } elseif ($objecttype == 'propal') { $classpath = 'comm/propal/class'; @@ -1838,52 +1845,52 @@ function dolGetElementUrl($objectid, $objecttype, $withpicto = 0, $option = '') } elseif ($objecttype == 'shipping') { $classpath = 'expedition/class'; - $subelement = 'expedition'; + $myobject = 'expedition'; $module = 'expedition_bon'; } elseif ($objecttype == 'delivery') { $classpath = 'livraison/class'; - $subelement = 'livraison'; + $myobject = 'livraison'; $module = 'livraison_bon'; } elseif ($objecttype == 'contract') { $classpath = 'contrat/class'; $module='contrat'; - $subelement='contrat'; + $myobject='contrat'; } elseif ($objecttype == 'member') { $classpath = 'adherents/class'; $module='adherent'; - $subelement='adherent'; + $myobject='adherent'; } elseif ($objecttype == 'cabinetmed_cons') { $classpath = 'cabinetmed/class'; $module='cabinetmed'; - $subelement='cabinetmedcons'; + $myobject='cabinetmedcons'; } elseif ($objecttype == 'fichinter') { $classpath = 'fichinter/class'; $module='ficheinter'; - $subelement='fichinter'; + $myobject='fichinter'; } elseif ($objecttype == 'task') { $classpath = 'projet/class'; $module='projet'; - $subelement='task'; + $myobject='task'; } elseif ($objecttype == 'stock') { $classpath = 'product/stock/class'; $module='stock'; - $subelement='stock'; + $myobject='stock'; } elseif ($objecttype == 'inventory') { $classpath = 'product/inventory/class'; $module='stock'; - $subelement='inventory'; + $myobject='inventory'; } // Generic case for $classfile and $classname - $classfile = strtolower($subelement); $classname = ucfirst($subelement); + $classfile = strtolower($myobject); $classname = ucfirst($myobject); //print "objecttype=".$objecttype." module=".$module." subelement=".$subelement." classfile=".$classfile." classname=".$classname; if ($objecttype == 'invoice_supplier') { @@ -1903,6 +1910,7 @@ function dolGetElementUrl($objectid, $objecttype, $withpicto = 0, $option = '') $classfile = 'entrepot'; $classname = 'Entrepot'; } + if (!empty($conf->$module->enabled)) { $res = dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); @@ -2048,12 +2056,14 @@ function cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent) /** * Get an array with properties of an element * - * @param string $element_type Element type: 'action', 'facture', 'project_task' or 'object@modulext'... + * @param string $element_type Element type: 'action', 'facture', 'project_task' or 'object@mymodule'... * @return array (module, classpath, element, subelement, classfile, classname) */ function getElementProperties($element_type) { - // Parse element/subelement (ex: project_task) + $regs = array(); + + // Parse element/subelement (ex: project_task) $module = $element_type; $element = $element_type; $subelement = $element_type; diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 2d28495cdc3..65d013992be 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -571,7 +571,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // List of actions on element include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'myobject', (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright); + $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright); print ''; }