Clean code for order of modules

This commit is contained in:
Laurent Destailleur 2019-10-17 19:21:30 +02:00
parent 87ec1de78e
commit de396dc9b3
5 changed files with 31 additions and 16 deletions

View File

@ -63,8 +63,6 @@ $dolistore = new Dolistore(false);
if (! $user->admin)
accessforbidden();
$specialtostring=array(0=>'common', 1=>'interfaces', 2=>'other', 3=>'functional', 4=>'marketplace');
$familyinfo=array(
'hr'=>array('position'=>'001', 'label'=>$langs->trans("ModuleFamilyHr")),
'crm'=>array('position'=>'006', 'label'=>$langs->trans("ModuleFamilyCrm")),
@ -368,11 +366,8 @@ foreach ($modulesdir as $dir)
}
}
ksort($arrayofnatures);
}
// Define array $categ with categ with at least one qualified module
if ($modulequalified > 0)
{
// Define array $categ with categ with at least one qualified module
$filename[$i]= $modName;
$modules[$modName] = $objMod;
@ -400,7 +395,15 @@ foreach ($modulesdir as $dir)
$arrayofwarningsext[$modName]=$objMod->warnings_activation_ext;
}
$orders[$i] = $familyinfo[$familykey]['position']."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number
$familyposition = $familyinfo[$familykey]['position'];
if ($external)
{
// TODO Find a solution so modules with their own family are always at end
//var_dump($familyposition);
//$familyposition += 100;
}
$orders[$i] = $familyposition."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number
$dirmod[$i] = $dir;
//print $i.'-'.$dirmod[$i].'<br>';
// Set categ[$i]
@ -527,6 +530,7 @@ if ($mode == 'common')
print '<div class="clearboth"></div><br>';
$object=new stdClass();
$parameters=array();
$reshook=$hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@ -538,14 +542,13 @@ if ($mode == 'common')
foreach ($orders as $key => $value)
{
$tab=explode('_', $value);
$familyposition=$tab[0]; $familykey=$tab[1]; $module_position=$tab[2]; $numero=$tab[3];
$familykey=$tab[1];
$module_position=$tab[2];
$modName = $filename[$key];
$objMod = $modules[$modName];
$dirofmodule = $dirmod[$key];
//print $objMod->name." - ".$key." - ".$objMod->version."<br>";
//if (($mode != (isset($specialtostring[$special])?$specialtostring[$special]:'unknown') && $mode != 'expdev')
if ($mode == 'expdev' && $objMod->version != 'development' && $objMod->version != 'experimental') continue; // Discard if not for current tab
if (! $objMod->getName())

View File

@ -59,7 +59,7 @@ class modDataPolicy extends DolibarrModules {
// It is used to group modules by family in module setup page
$this->family = "technic";
// Module position in the family on 2 digits ('01', '10', '20', ...)
$this->module_position = '81';
$this->module_position = '78';
// Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
//$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
// Module label (no space allowed), used if translation string 'ModuledatapolicyName' not found (MyModue is name of module).

View File

@ -45,7 +45,7 @@ class modDocumentGeneration extends DolibarrModules
$this->numero = 1520;
$this->family = "technic";
$this->module_position = '80';
$this->module_position = '78';
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i', '', get_class($this));
$this->description = "Direct mail document generation";

View File

@ -42,14 +42,14 @@ class modZapier extends DolibarrModules
$this->db = $db;
// Id for module (must be unique).
// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
$this->numero = 792000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
$this->numero = 50330;
// Key text used to identify module (for permissions, menus, etc...)
$this->rights_class = 'zapier';
// Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
// It is used to group modules by family in module setup page
$this->family = "interface";
// Module position in the family on 2 digits ('01', '10', '20', ...)
$this->module_position = 100;
$this->module_position = '13';
// Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
//$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
// Module label (no space allowed), used if translation string 'ModuleZapierName' not found (Zapier is name of module).

View File

@ -283,7 +283,7 @@ print '<td>'.$langs->trans("Permissions").'</td>';
print '</tr>'."\n";
//print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS;
$sql = "SELECT r.id, r.libelle, r.module";
$sql = "SELECT r.id, r.libelle, r.module, r.module_position";
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
$sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
$sql.= " AND r.entity = " . $entity;
@ -301,12 +301,24 @@ if ($result)
{
$obj = $db->fetch_object($result);
// Si la ligne correspond a un module qui n'existe plus (absent de includes/module), on l'ignore
// If line is for a module that doe snot existe anymore (absent of includes/module), we ignore it
if (empty($modules[$obj->module]))
{
$i++;
continue;
}
// Fix field module_position in database if value is still zero
if (empty($obj->module_position))
{
if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0))
{
$sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def set module_position = ".$modules[$obj->module]->module_position;
$sqlupdate.= " WHERE module_position = 0 AND module = '".$db->escape($obj->module)."'";
$db->query($sqlupdate);
}
}
if (isset($obj->module) && ($oldmod <> $obj->module))
{
$oldmod = $obj->module;