From e00704c36d92ce323f535457a4c4ce41fb1f959f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 16 Feb 2011 20:54:24 +0000 Subject: [PATCH] Perf: Speed enhancement. Reduce one request for each page call. --- htdocs/core/class/menubase.class.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index d9d7792fae4..83f3b144d07 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -430,6 +430,7 @@ class Menubase * @param mainmenu Value for mainmenu that defined top menu * @param menu_handler Name of menu_handler used (auguria, eldy...) * @return array Return array with menu entries for top menu + * TODO Mutualize menuTopCharger and menuLeftCharger */ function menuTopCharger($type_user, $mainmenu, $menu_handler) { @@ -542,6 +543,7 @@ class Menubase global $langs, $user, $conf, $leftmenu; // To export to dol_eval function global $rights; // To export to dol_eval function + $menutopid=''; $leftmenu=$myleftmenu; $this->newmenu = $newmenu; @@ -549,7 +551,7 @@ class Menubase $tabMenu = array (); - $sql = "SELECT m.rowid, m.fk_menu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu"; + $sql = "SELECT m.rowid, m.type, m.fk_menu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " WHERE m.menu_handler in('".$menu_handler."','all')"; $sql.= " AND m.entity = ".$conf->entity; @@ -572,6 +574,9 @@ class Menubase //$objm = $this->db->fetch_object($resql); $menu = $this->db->fetch_array($resql); + // Detect if it's top menu line + if ($menu['type'] == 'top' && $menu['mainmenu'] == $mainmenu) $menutopid=$menu['rowid']; + // Define $chaine $chaine=""; $title = $langs->trans($menu['titre']); @@ -644,21 +649,23 @@ class Menubase } // Get menutopid - $menutopid=''; - - $sql = "SELECT m.rowid, m.titre, m.type"; + /*$sql = "SELECT m.rowid, m.titre, m.type"; $sql.= " FROM " . MAIN_DB_PREFIX . "menu as m"; $sql.= " WHERE m.mainmenu = '".$mainmenu."'"; $sql.= " AND m.menu_handler in('".$menu_handler."','all')"; $sql.= " AND m.entity = ".$conf->entity; + if ($type_user == 0) $sql.= " AND m.usertype in (0,2)"; + if ($type_user == 1) $sql.= " AND m.usertype in (1,2)"; $sql.= " AND type = 'top'"; + dol_syslog("Menubase::menuLeftCharger sql=".$sql); // It should have only one response $resql = $this->db->query($sql); $menutop = $this->db->fetch_object($resql); if ($menutop) $menutopid=$menutop->rowid; $this->db->free($resql); //print "menutopid=".$menutopid." sql=".$sql; + */ // Now edit this->newmenu to add entries in tabMenu that are in childs $this->recur($tabMenu, $menutopid, 1);