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.
This commit is contained in:
Laurent Destailleur 2013-01-15 15:42:39 +01:00
parent ec5b4f5fa7
commit db1cd6b27f
6 changed files with 197 additions and 339 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> /* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -31,46 +31,13 @@
/** /**
* Classe permettant la gestion du menu du haut Auguria * Classe permettant la gestion du menu du haut Auguria
*/ */
class MenuTop class MenuManager
{ {
var $db; var $db;
var $require_left=array("auguria_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier 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 $type_user=0; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens 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;
var $menu_array_after; var $menu_array_after;
@ -82,7 +49,7 @@ class MenuLeft
* @param array &$menu_array Table of menu entries to show before entries of menu 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 * @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->db=$db;
$this->menu_array=$menu_array; $this->menu_array=$menu_array;
@ -93,16 +60,20 @@ class MenuLeft
/** /**
* Show menu * Show menu
* *
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown * @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; return $res;
} }
} }
?> ?>

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com> /* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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 * Classe permettant la gestion du menu du haut Auguria
*/ */
class MenuTop class MenuManager
{ {
var $db; var $db;
var $require_left=array("auguria_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier var $require_left=array("auguria_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier
@ -39,39 +39,6 @@ class MenuTop
var $atarget=""; // Valeur du target a utiliser dans les liens 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;
var $menu_array_after; var $menu_array_after;
@ -83,7 +50,7 @@ class MenuLeft
* @param array &$menu_array Table of menu entries to show before entries of menu 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 * @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->db=$db;
$this->menu_array=$menu_array; $this->menu_array=$menu_array;
@ -94,19 +61,22 @@ class MenuLeft
/** /**
* Show menu * Show menu
* *
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown * @return int Number of menu entries shown
*/ */
function showmenu() function showmenu($mode)
{ {
global $conf; global $conf;
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);
$conf->global->MAIN_SEARCHFORM_SOCIETE=0; $conf->global->MAIN_SEARCHFORM_SOCIETE=0;
$conf->global->MAIN_SEARCHFORM_CONTACT=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; return $res;
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007-2010 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2007-2010 Regis Houssin <regis.houssin@capnetworks.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 $db;
var $require_left=array("eldy_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier 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 $type_user=0; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens 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;
var $menu_array_after; 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 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 * @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->db=$db;
$this->menu_array=$menu_array; $this->menu_array=$menu_array;
@ -93,13 +59,16 @@ class MenuLeft
/** /**
* Show menu * Show menu
* *
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown * @return int Number of menu entries shown
*/ */
function showmenu() function showmenu($mode)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; 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; return $res;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007-2009 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2007-2009 Regis Houssin <regis.houssin@capnetworks.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 $db;
var $require_left=array("eldy_frontoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier 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 $type_user=1; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens 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;
var $menu_array_after; var $menu_array_after;
@ -92,19 +59,22 @@ class MenuLeft
/** /**
* Show menu * Show menu
* *
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown * @return int Number of menu entries shown
*/ */
function showmenu() function showmenu($mode)
{ {
global $conf; global $conf;
require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; 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_SOCIETE=0;
$conf->global->MAIN_SEARCHFORM_CONTACT=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; return $res;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,37 +21,46 @@
*/ */
/** /**
* \class MenuTop * Class to manage empty menu
* \brief Class for top empty menu
*/ */
class MenuTop class MenuManager
{ {
var $db; 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 $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 * @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) function __construct($db, &$menu_array, &$menu_array_after)
{ {
$this->db=$db; $this->db=$db;
$this->menu_array=$menu_array;
$this->menu_array_after=$menu_array_after;
} }
/** /**
* Show menu * Show menu
* *
* @param string $mode 'top' or 'left'
* @return void * @return void
*/ */
function showmenu() function showmenu($mode)
{ {
global $user,$conf,$langs,$dolibarr_main_db_name; global $user,$conf,$langs,$dolibarr_main_db_name;
if ($mode == 'top')
{
print_start_menu_array_empty(); print_start_menu_array_empty();
$idsel='home'; $idsel='home';
@ -69,108 +78,8 @@ class MenuTop
print_end_menu_array_empty(); print_end_menu_array_empty();
} }
} if ($mode == 'left')
/**
* Output menu entry
*
* @return void
*/
function print_start_menu_array_empty()
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '<table class="tmenu" summary="topmenu"><tr class="tmenu">';
else print '<ul class="tmenu">';
}
/**
* Output start menu entry
*
* @param string $idsel Text
* @return void
*/
function print_start_menu_entry_empty($idsel)
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '<td class="tmenu" id="mainmenutd_'.$idsel.'">';
else print '<li class="tmenu" id="mainmenutd_'.$idsel.'">';
}
/**
* Output menu entry
*
* @param string $text Text
* @return void
*/
function print_text_menu_entry_empty($text)
{
global $conf;
print '<span class="mainmenuaspan">';
print $text;
print '</span>';
}
/**
* Output end menu entry
*
* @return void
*/
function print_end_menu_entry_empty()
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '</td>';
else print '</li>';
print "\n";
}
/**
* Output menu array
*
* @return void
*/
function print_end_menu_array_empty()
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '</tr></table>';
else print '</ul>';
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(); $newmenu = new Menu();
// Put here left menu entries // Put here left menu entries
@ -184,11 +93,13 @@ class MenuLeft
$newmenu->add("/admin/ihm.php", $langs->trans("GUISetup"),1); $newmenu->add("/admin/ihm.php", $langs->trans("GUISetup"),1);
$newmenu->add("/admin/boxes.php", $langs->trans("Boxes"),1); $newmenu->add("/admin/boxes.php", $langs->trans("Boxes"),1);
$newmenu->add("/admin/delais.php",$langs->trans("Alerts"),1); $newmenu->add("/admin/delais.php",$langs->trans("Alerts"),1);
$newmenu->add("/admin/perms.php", $langs->trans("Security"),1); $newmenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"),1);
$newmenu->add("/admin/mails.php", $langs->trans("EMails"),1); $newmenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"),1);
$newmenu->add("/admin/limits.php", $langs->trans("Limits"),1); $newmenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"),1);
$newmenu->add("/admin/dict.php", $langs->trans("DictionnarySetup"),1); $newmenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"),1);
$newmenu->add("/admin/const.php", $langs->trans("OtherSetup"),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 ***** // ***** END *****
@ -256,7 +167,73 @@ class MenuLeft
} }
} }
} }
}
}
/**
* Output menu entry
*
* @return void
*/
function print_start_menu_array_empty()
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '<table class="tmenu" summary="topmenu"><tr class="tmenu">';
else print '<ul class="tmenu">';
}
/**
* Output start menu entry
*
* @param string $idsel Text
* @return void
*/
function print_start_menu_entry_empty($idsel)
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '<td class="tmenu" id="mainmenutd_'.$idsel.'">';
else print '<li class="tmenu" id="mainmenutd_'.$idsel.'">';
}
/**
* Output menu entry
*
* @param string $text Text
* @return void
*/
function print_text_menu_entry_empty($text)
{
global $conf;
print '<span class="mainmenuaspan">';
print $text;
print '</span>';
}
/**
* Output end menu entry
*
* @return void
*/
function print_end_menu_entry_empty()
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '</td>';
else print '</li>';
print "\n";
}
/**
* Output menu array
*
* @return void
*/
function print_end_menu_array_empty()
{
global $conf;
if (preg_match('/bluelagoon|eldy|freelug|rodolphe|yellow|dev/',$conf->css)) print '</tr></table>';
else print '</ul>';
print "\n";
} }
?> ?>

View File

@ -1271,7 +1271,7 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php if (GETPOST('menu')) $top_menu=GETPOST('menu'); // menu=eldy_backoffice.php
// Load the top menu manager (only if not already done) // Load the top menu manager (only if not already done)
if (! class_exists('MenuTop')) if (! class_exists('MenuManager'))
{ {
$menufound=0; $menufound=0;
$dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']); $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
@ -1296,9 +1296,10 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
print '<div id="tmenu_tooltip" class="tmenu">'."\n"; print '<div id="tmenu_tooltip" class="tmenu">'."\n";
// Show menu // Show menu
$menutop = new MenuTop($db); $dummy1=array();$dummy2=array();
$menutop = new MenuManager($db,$dummy1,$dummy2);
$menutop->atarget=$target; $menutop->atarget=$target;
$menutop->showmenu(); // This contains a \n $menutop->showmenu('top'); // This contains a \n
print "</div>\n"; print "</div>\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; $left_menu=empty($conf->browser->phone)?$conf->top_menu:$conf->smart_menu;
if (GETPOST('menu')) $left_menu=GETPOST('menu'); // menu=eldy_backoffice.php if (GETPOST('menu')) $left_menu=GETPOST('menu'); // menu=eldy_backoffice.php
// Load the top menu manager (only if not already done) // Load the menu manager (only if not already done)
if (! class_exists('MenuLeft')) if (! class_exists('MenuManager'))
{ {
$menufound=0; $menufound=0;
$dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']); $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 '<div class="vmenu">'."\n"; print '<div class="vmenu">'."\n";
$menuleft=new MenuLeft($db,$menu_array_before,$menu_array_after); $menuleft=new MenuManager($db,$menu_array_before,$menu_array_after);
$menuleft->showmenu(); // output menu_array and menu found in database $menuleft->showmenu('left'); // output menu_array and menu found in database
// Show other forms // Show other forms