From db1cd6b27f455746cd1ca4158c4dfaba2329f8ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 15 Jan 2013 15:42:39 +0100 Subject: [PATCH] Qual: Merge the 2 class MenuTop and MenuLeft into menu handler file into 1 class MenuManager. This make code simpler and is also a first step to optimize performance of menu loading. --- .../menus/standard/auguria_backoffice.php | 65 ++-- .../menus/standard/auguria_frontoffice.php | 62 +--- .../core/menus/standard/eldy_backoffice.php | 51 +-- .../core/menus/standard/eldy_frontoffice.php | 48 +-- htdocs/core/menus/standard/empty.php | 293 ++++++++---------- htdocs/main.inc.php | 17 +- 6 files changed, 197 insertions(+), 339 deletions(-) diff --git a/htdocs/core/menus/standard/auguria_backoffice.php b/htdocs/core/menus/standard/auguria_backoffice.php index 2d8fba928f3..bad8c3d1507 100644 --- a/htdocs/core/menus/standard/auguria_backoffice.php +++ b/htdocs/core/menus/standard/auguria_backoffice.php @@ -1,7 +1,7 @@ * Copyright (C) 2009 Regis Houssin - * Copyright (C) 2008-2009 Laurent Destailleur + * Copyright (C) 2008-2013 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,78 +31,49 @@ /** * Classe permettant la gestion du menu du haut Auguria */ -class MenuTop +class MenuManager { var $db; var $require_left=array("auguria_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier var $type_user=0; // Put 0 for internal users, 1 for external users var $atarget=""; // Valeur du target a utiliser dans les liens + var $menu_array; + var $menu_array_after; - /** + + /** * Constructor * - * @param DoliDb $db Database handler - */ - function __construct($db) - { - $this->db=$db; - } - - - /** - * Show menu - * - * @return void - */ - function showmenu() - { - require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php'; - - print_auguria_menu($this->db,$this->atarget,$this->type_user); - } - -} - - -/** - * Classe permettant la gestion du menu du gauche Auguria - */ -class MenuLeft -{ - var $db; - var $menu_array; - var $menu_array_after; - - - /** - * Constructor - * * @param DoliDB $db Database handler * @param array &$menu_array Table of menu entries to show before entries of menu handler * @param array &$menu_array_after Table of menu entries to show after entries of menu handler */ - function __construct($db,&$menu_array,&$menu_array_after) + function __construct($db, &$menu_array, &$menu_array_after) { $this->db=$db; $this->menu_array=$menu_array; $this->menu_array_after=$menu_array_after; } - + /** - * Show menu + * Show menu * - * @return int Number of menu entries shown + * @param string $mode 'top' or 'left' + * @return int Number of menu entries shown */ - function showmenu() + function showmenu($mode) { - require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php'; - $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after); + $res='ErrorBadParameterForMode'; + if ($mode == 'top') $res=print_auguria_menu($this->db,$this->atarget,$this->type_user); + if ($mode == 'left') $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after); return $res; - } + } + } ?> diff --git a/htdocs/core/menus/standard/auguria_frontoffice.php b/htdocs/core/menus/standard/auguria_frontoffice.php index 8432a29e9af..73a22696eb0 100644 --- a/htdocs/core/menus/standard/auguria_frontoffice.php +++ b/htdocs/core/menus/standard/auguria_frontoffice.php @@ -1,7 +1,7 @@ * Copyright (C) 2009 Regis Houssin - * Copyright (C) 2008-2009 Laurent Destailleur + * Copyright (C) 2008-2013 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ /** * Classe permettant la gestion du menu du haut Auguria */ -class MenuTop +class MenuManager { var $db; var $require_left=array("auguria_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier @@ -39,43 +39,10 @@ class MenuTop var $atarget=""; // Valeur du target a utiliser dans les liens - /** - * Constructor - * - * @param DoliDb $db Database handler - */ - function __construct($db) - { - $this->db=$db; - } - - - - /** - * Show menu - * - * @return void - */ - function showmenu() - { - require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php'; - - print_auguria_menu($this->db,$this->atarget,$this->type_user); - } - -} - - -/** - * Classe permettant la gestion du menu du gauche Auguria - */ -class MenuLeft -{ - var $db; - var $menu_array; - var $menu_array_after; - + var $menu_array; + var $menu_array_after; + /** * Constructor * @@ -83,29 +50,32 @@ class MenuLeft * @param array &$menu_array Table of menu entries to show before entries of menu handler * @param array &$menu_array_after Table of menu entries to show after entries of menu handler */ - function __construct($db,&$menu_array,&$menu_array_after) + function __construct($db, &$menu_array, &$menu_array_after) { $this->db=$db; $this->menu_array=$menu_array; $this->menu_array_after=$menu_array_after; } - + /** * Show menu * - * @return int Number of menu entries shown - */ - function showmenu() - { + * @param string $mode 'top' or 'left' + * @return int Number of menu entries shown + */ + function showmenu($mode) + { global $conf; require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php'; - $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after); - $conf->global->MAIN_SEARCHFORM_SOCIETE=0; $conf->global->MAIN_SEARCHFORM_CONTACT=0; + + $res='ErrorBadParameterForMode'; + if ($mode == 'top') $res=print_auguria_menu($this->db,$this->atarget,$this->type_user); + if ($mode == 'left') $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after); return $res; } diff --git a/htdocs/core/menus/standard/eldy_backoffice.php b/htdocs/core/menus/standard/eldy_backoffice.php index 3baf9cd2ab0..82b3837f66d 100644 --- a/htdocs/core/menus/standard/eldy_backoffice.php +++ b/htdocs/core/menus/standard/eldy_backoffice.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2013 Laurent Destailleur * Copyright (C) 2007-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -28,49 +28,15 @@ /** - * Class to manage top menu Eldy (for internal users) + * Classe to manage menu Eldy */ -class MenuTop +class MenuManager { var $db; var $require_left=array("eldy_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier var $type_user=0; // Put 0 for internal users, 1 for external users var $atarget=""; // Valeur du target a utiliser dans les liens - - /** - * Constructor - * - * @param DoliDb $db Database handler - */ - function __construct($db) - { - $this->db=$db; - } - - - /** - * Show menu - * - * @return void - */ - function showmenu() - { - require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; - - print_eldy_menu($this->db,$this->atarget,$this->type_user); - } - -} - - -/** - * \class MenuLeft - * \brief Classe permettant la gestion du menu du gauche Eldy - */ -class MenuLeft -{ - var $db; var $menu_array; var $menu_array_after; @@ -82,7 +48,7 @@ class MenuLeft * @param array &$menu_array Table of menu entries to show before entries of menu handler * @param array &$menu_array_after Table of menu entries to show after entries of menu handler */ - function __construct($db,&$menu_array,&$menu_array_after) + function __construct($db, &$menu_array, &$menu_array_after) { $this->db=$db; $this->menu_array=$menu_array; @@ -93,13 +59,16 @@ class MenuLeft /** * Show menu * - * @return int Number of menu entries shown + * @param string $mode 'top' or 'left' + * @return int Number of menu entries shown */ - function showmenu() + function showmenu($mode) { require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; - $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after); + $res='ErrorBadParameterForMode'; + if ($mode == 'top') $res=print_eldy_menu($this->db,$this->atarget,$this->type_user); + if ($mode == 'left') $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after); return $res; } diff --git a/htdocs/core/menus/standard/eldy_frontoffice.php b/htdocs/core/menus/standard/eldy_frontoffice.php index 9aec7ac62a4..ecc1b0c1b94 100644 --- a/htdocs/core/menus/standard/eldy_frontoffice.php +++ b/htdocs/core/menus/standard/eldy_frontoffice.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2013 Laurent Destailleur * Copyright (C) 2007-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -28,48 +28,15 @@ /** - * Class to manage top menu Eldy (for external users) + * Class to manage menu Eldy (for external users) */ -class MenuTop +class MenuManager { var $db; var $require_left=array("eldy_frontoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier var $type_user=1; // Put 0 for internal users, 1 for external users var $atarget=""; // Valeur du target a utiliser dans les liens - - /** - * Constructor - * - * @param DoliDb $db Database handler - */ - function __construct($db) - { - $this->db=$db; - } - - - /** - * Show menu - * - * @return void - */ - function showmenu() - { - require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; - - print_eldy_menu($this->db,$this->atarget,$this->type_user); - } - -} - - -/** - * Classe permettant la gestion du menu du gauche Eldy - */ -class MenuLeft -{ - var $db; var $menu_array; var $menu_array_after; @@ -92,19 +59,22 @@ class MenuLeft /** * Show menu * + * @param string $mode 'top' or 'left' * @return int Number of menu entries shown */ - function showmenu() + function showmenu($mode) { global $conf; require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; - $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after); - $conf->global->MAIN_SEARCHFORM_SOCIETE=0; $conf->global->MAIN_SEARCHFORM_CONTACT=0; + $res='ErrorBadParameterForMode'; + if ($mode == 'top') $res=print_eldy_menu($this->db,$this->atarget,$this->type_user); + if ($mode == 'left') $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after); + return $res; } diff --git a/htdocs/core/menus/standard/empty.php b/htdocs/core/menus/standard/empty.php index f67ded5b41f..411b98d52a4 100644 --- a/htdocs/core/menus/standard/empty.php +++ b/htdocs/core/menus/standard/empty.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2006-2013 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,56 +21,156 @@ */ /** - * \class MenuTop - * \brief Class for top empty menu + * Class to manage empty menu */ -class MenuTop +class MenuManager { var $db; - var $require_left=array("empty"); // If this top menu handler must be used with a particular left menu handler + var $require_left=array("empty"); // If this top menu handler must be used with a particular left menu handler var $type_user=0; // Put 0 for internal users, 1 for external users - var $atarget=""; // To store arget to use in menu links + var $atarget=""; // To store arget to use in menu links + + var $menu_array; + var $menu_array_after; - /** - * Constructor + /** + * Constructor * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db=$db; - } + * @param DoliDB $db Database handler + * @param array &$menu_array Table of menu entries to show before entries of menu handler + * @param array &$menu_array_after Table of menu entries to show after entries of menu handler + */ + function __construct($db, &$menu_array, &$menu_array_after) + { + $this->db=$db; + $this->menu_array=$menu_array; + $this->menu_array_after=$menu_array_after; + } - /** - * Show menu - * - * @return void - */ - function showmenu() - { - global $user,$conf,$langs,$dolibarr_main_db_name; + /** + * Show menu + * + * @param string $mode 'top' or 'left' + * @return void + */ + function showmenu($mode) + { + global $user,$conf,$langs,$dolibarr_main_db_name; - print_start_menu_array_empty(); + if ($mode == 'top') + { + print_start_menu_array_empty(); - $idsel='home'; - $classname='class="tmenu"'; + $idsel='home'; + $classname='class="tmenu"'; - print_start_menu_entry_empty($idsel); - print 'atarget?' target="'.$this->atarget.'"':'').'>'; - print ''; - print ''; - print 'atarget?' target="'.$this->atarget.'"':'').'>'; - print_text_menu_entry_empty($langs->trans("Home")); - print ''; - print_end_menu_entry_empty(); + print_start_menu_entry_empty($idsel); + print 'atarget?' target="'.$this->atarget.'"':'').'>'; + print ''; + print ''; + print 'atarget?' target="'.$this->atarget.'"':'').'>'; + print_text_menu_entry_empty($langs->trans("Home")); + print ''; + print_end_menu_entry_empty(); - print_end_menu_array_empty(); - } + print_end_menu_array_empty(); + } + if ($mode == 'left') + { + $newmenu = new Menu(); + + // Put here left menu entries + // ***** START ***** + + $langs->load("admin"); // Load translation file admin.lang + $newmenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"),0); + $newmenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"),1); + $newmenu->add("/admin/modules.php", $langs->trans("Modules"),1); + $newmenu->add("/admin/menus.php", $langs->trans("Menus"),1); + $newmenu->add("/admin/ihm.php", $langs->trans("GUISetup"),1); + $newmenu->add("/admin/boxes.php", $langs->trans("Boxes"),1); + $newmenu->add("/admin/delais.php",$langs->trans("Alerts"),1); + $newmenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"),1); + $newmenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"),1); + $newmenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"),1); + $newmenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"),1); + $newmenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"),1); + $newmenu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionnarySetup"),1); + $newmenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"),1); + + // ***** END ***** + + // do not change code after this + + // override menu_array by value array in $newmenu + $this->menu_array=$newmenu->liste; + + $alt=0; + $num=count($this->menu_array); + for ($i = 0; $i < $num; $i++) + { + $alt++; + if (empty($this->menu_array[$i]['level'])) + { + if (($alt%2==0)) + { + print '
'."\n"; + } + else + { + print '
'."\n"; + } + } + + // Place tabulation + $tabstring=''; + $tabul=($this->menu_array[$i]['level'] - 1); + if ($tabul > 0) + { + for ($j=0; $j < $tabul; $j++) + { + $tabstring.='   '; + } + } + + if ($this->menu_array[$i]['level'] == 0) { + if ($this->menu_array[$i]['enabled']) + { + print ''."\n"; + } + else + { + print ''."\n"; + } + print ''."\n"; + } + + if ($this->menu_array[$i]['level'] > 0) { + print ''."\n"; + } + + // If next is a new block or end + if (empty($this->menu_array[$i+1]['level'])) + { + print ''."\n"; + print "
\n"; + } + } + } + } } + /** * Output menu entry * @@ -136,127 +236,4 @@ function print_end_menu_array_empty() print "\n"; } - - -/** - * Class for left empty menu - */ -class MenuLeft -{ - var $db; - var $menu_array; - var $menu_array_after; - - - /** - * Constructor - * - * @param DoliDB $db Database handler - * @param array &$menu_array Table of menu entries to show before entries of menu handler - * @param array &$menu_array_after Table of menu entries to show after entries of menu handler - */ - function __construct($db,&$menu_array,&$menu_array_after) - { - $this->db=$db; - $this->menu_array=$menu_array; - $this->menu_array_after=$menu_array_after; - } - - - /** - * Show menu - * - * @return void - */ - function showmenu() - { - global $user,$conf,$langs,$dolibarr_main_db_name; - $newmenu = new Menu(); - - // Put here left menu entries - // ***** START ***** - - $langs->load("admin"); // Load translation file admin.lang - $newmenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"),0); - $newmenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"),1); - $newmenu->add("/admin/modules.php", $langs->trans("Modules"),1); - $newmenu->add("/admin/menus.php", $langs->trans("Menus"),1); - $newmenu->add("/admin/ihm.php", $langs->trans("GUISetup"),1); - $newmenu->add("/admin/boxes.php", $langs->trans("Boxes"),1); - $newmenu->add("/admin/delais.php",$langs->trans("Alerts"),1); - $newmenu->add("/admin/perms.php", $langs->trans("Security"),1); - $newmenu->add("/admin/mails.php", $langs->trans("EMails"),1); - $newmenu->add("/admin/limits.php", $langs->trans("Limits"),1); - $newmenu->add("/admin/dict.php", $langs->trans("DictionnarySetup"),1); - $newmenu->add("/admin/const.php", $langs->trans("OtherSetup"),1); - - // ***** END ***** - - // do not change code after this - - // override menu_array by value array in $newmenu - $this->menu_array=$newmenu->liste; - - $alt=0; - $num=count($this->menu_array); - for ($i = 0; $i < $num; $i++) - { - $alt++; - if (empty($this->menu_array[$i]['level'])) - { - if (($alt%2==0)) - { - print '
'."\n"; - } - else - { - print '
'."\n"; - } - } - - // Place tabulation - $tabstring=''; - $tabul=($this->menu_array[$i]['level'] - 1); - if ($tabul > 0) - { - for ($j=0; $j < $tabul; $j++) - { - $tabstring.='   '; - } - } - - if ($this->menu_array[$i]['level'] == 0) { - if ($this->menu_array[$i]['enabled']) - { - print ''."\n"; - } - else - { - print ''."\n"; - } - print ''."\n"; - } - - if ($this->menu_array[$i]['level'] > 0) { - print ''."\n"; - } - - // If next is a new block or end - if (empty($this->menu_array[$i+1]['level'])) - { - print ''."\n"; - print "
\n"; - } - } - } - -} - ?> \ No newline at end of file diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 97d5d78f467..6ce1cb50971 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1271,13 +1271,13 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php // Load the top menu manager (only if not already done) - if (! class_exists('MenuTop')) + if (! class_exists('MenuManager')) { $menufound=0; $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']); foreach($dirmenus as $dirmenu) { - $menufound=dol_include_once($dirmenu."standard/".$top_menu); + $menufound=dol_include_once($dirmenu."standard/".$top_menu); if ($menufound) break; } if (! $menufound) // If failed to include, we try with standard @@ -1296,9 +1296,10 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a print '
'."\n"; // Show menu - $menutop = new MenuTop($db); + $dummy1=array();$dummy2=array(); + $menutop = new MenuManager($db,$dummy1,$dummy2); $menutop->atarget=$target; - $menutop->showmenu(); // This contains a \n + $menutop->showmenu('top'); // This contains a \n print "
\n"; @@ -1483,8 +1484,8 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me $left_menu=empty($conf->browser->phone)?$conf->top_menu:$conf->smart_menu; if (GETPOST('menu')) $left_menu=GETPOST('menu'); // menu=eldy_backoffice.php - // Load the top menu manager (only if not already done) - if (! class_exists('MenuLeft')) + // Load the menu manager (only if not already done) + if (! class_exists('MenuManager')) { $menufound=0; $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']); @@ -1505,8 +1506,8 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me print '
'."\n"; - $menuleft=new MenuLeft($db,$menu_array_before,$menu_array_after); - $menuleft->showmenu(); // output menu_array and menu found in database + $menuleft=new MenuManager($db,$menu_array_before,$menu_array_after); + $menuleft->showmenu('left'); // output menu_array and menu found in database // Show other forms