From 9a3dd8dba6a2729a4f457e4ceb87e90de426f052 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Sat, 12 Jan 2013 16:27:12 +0000 Subject: [PATCH] Ajout classe SousMenus --- .gitattributes | 3 + library/ZendAfi/View/Helper/Accueil/Base.php | 2 +- library/ZendAfi/View/Helper/Menu/Base.php | 21 ++----- library/ZendAfi/View/Helper/Menu/Boite.php | 41 +++++++++++++ library/ZendAfi/View/Helper/Menu/Entry.php | 44 +++++++++++--- library/ZendAfi/View/Helper/Menu/Menus.php | 57 +++++++++++++++++++ .../ZendAfi/View/Helper/Menu/SousMenus.php | 27 +++++++++ .../ZendAfi/View/Helper/MenuHorizontal.php | 34 ++--------- .../ZendAfi/View/Helper/ModuleAbstract.php | 1 - 9 files changed, 174 insertions(+), 56 deletions(-) create mode 100644 library/ZendAfi/View/Helper/Menu/Boite.php create mode 100644 library/ZendAfi/View/Helper/Menu/Menus.php create mode 100644 library/ZendAfi/View/Helper/Menu/SousMenus.php diff --git a/.gitattributes b/.gitattributes index 79c70aab592..dbfd8f04acc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2621,7 +2621,10 @@ library/ZendAfi/View/Helper/MapEvents.php -text library/ZendAfi/View/Helper/MapForLieu.php -text library/ZendAfi/View/Helper/MemoryFormat.php -text library/ZendAfi/View/Helper/Menu/Base.php -text +library/ZendAfi/View/Helper/Menu/Boite.php -text library/ZendAfi/View/Helper/Menu/Entry.php -text +library/ZendAfi/View/Helper/Menu/Menus.php -text +library/ZendAfi/View/Helper/Menu/SousMenus.php -text library/ZendAfi/View/Helper/MenuHorizontal.php -text library/ZendAfi/View/Helper/ModuleAbstract.php -text library/ZendAfi/View/Helper/NewsBibHelper.php -text diff --git a/library/ZendAfi/View/Helper/Accueil/Base.php b/library/ZendAfi/View/Helper/Accueil/Base.php index cfa60ed7ddb..5cf42893977 100644 --- a/library/ZendAfi/View/Helper/Accueil/Base.php +++ b/library/ZendAfi/View/Helper/Accueil/Base.php @@ -38,7 +38,7 @@ class ZendAfi_View_Helper_Accueil_Base extends ZendAfi_View_Helper_ModuleAbstrac */ public function __construct($id_module, $params) { parent::__construct($id_module, $params); - $this->id_module = $id_module; + $this->type_module = $params["type_module"]; $this->division = null; if (array_isset('division', $params)) diff --git a/library/ZendAfi/View/Helper/Menu/Base.php b/library/ZendAfi/View/Helper/Menu/Base.php index a9f43ac627b..20be31bce77 100644 --- a/library/ZendAfi/View/Helper/Menu/Base.php +++ b/library/ZendAfi/View/Helper/Menu/Base.php @@ -11,33 +11,24 @@ * * AFI-OPAC 2.0 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -abstract class ZendAfi_View_Helper_Menu_Base extends ZendAfi_View_Helper_ModuleAbstract { - public function __construct($id_module,$params) { - $params['type_module'] = $params['type_menu']; - parent::__construct($id_module, $params); - } - - +abstract class ZendAfi_View_Helper_Menu_Base extends ZendAfi_View_Helper_BaseHelper { public static function getModuleHelperFromParams($id_menu, $menu) { if (!array_isset('preferences', $menu)) $menu['preferences'] = array(); $menu['preferences']['picto'] = $menu['picto']; $menu['preferences']['libelle'] = $menu['libelle']; - if (Class_Systeme_ModulesMenu::isModuleAccueil($menu)) { - $menu['type_module'] = Class_Systeme_ModulesMenu::moduleAccueilType($menu); - return ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams($id_menu, $menu); - } - - return new ZendAfi_View_Helper_Menu_Entry($id_menu, $menu); + return Class_Systeme_ModulesMenu::isModuleAccueil($menu) + ? new ZendAfi_View_Helper_Menu_Boite($id_menu, $menu) + : new ZendAfi_View_Helper_Menu_Entry($id_menu, $menu); } } diff --git a/library/ZendAfi/View/Helper/Menu/Boite.php b/library/ZendAfi/View/Helper/Menu/Boite.php new file mode 100644 index 00000000000..15166bfba2c --- /dev/null +++ b/library/ZendAfi/View/Helper/Menu/Boite.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_View_Helper_Menu_Boite extends ZendAfi_View_Helper_BaseHelper { + protected $_id_module; + protected $_params; + + public function __construct($id_module, $params) { + parent::__construct(); + $this->_id_module = $id_module; + $this->_params = $params; + $this->_params['type_module'] = Class_Systeme_ModulesMenu::moduleAccueilType($params); + } + + public function getBoite() { + $helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams($this->_id_module, + $this->_params); + $helper->setView($this->view); + return $helper->getBoite(); + } +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Menu/Entry.php b/library/ZendAfi/View/Helper/Menu/Entry.php index 02c7803d499..851192ce56d 100644 --- a/library/ZendAfi/View/Helper/Menu/Entry.php +++ b/library/ZendAfi/View/Helper/Menu/Entry.php @@ -20,22 +20,48 @@ */ class ZendAfi_View_Helper_Menu_Entry extends ZendAfi_View_Helper_Menu_Base { + protected $_type_module; + protected $_preferences; + protected $_sous_menus; + + public function __construct($id_module,$params) { + parent::__construct(); + $this->_type_module = $params['type_menu']; + $this->_preferences = isset($params['preferences']) ? $params['preferences'] : []; + $this->_picto = $params['picto']; + $this->_libelle = $params['libelle']; + $this->_sous_menus = isset($params['sous_menus']) ? $params['sous_menus'] : null; + } + + public function getBoite() { + $html = $this->getTagAnchor(); + + if ($this->_sous_menus) { + $helper = new ZendAfi_View_Helper_Menu_SousMenus($this->_sous_menus); + $helper->setView($this->view); + $html .= $helper->getBoite(); + } + + return $html; + } + + + public function getTagAnchor() { $modMenus = new Class_Systeme_ModulesMenu(); - $params = $modMenus->getUrl($this->type_module, $this->preferences); + $params = $modMenus->getUrl($this->_type_module, $this->_preferences); $url = $params['url']; - if ($params['target']) - $target = "target='".$params['target']."'"; - else - $target = ''; + $target = $params['target'] + ? "target='".$params['target']."'"; + : ''; $anchor='<a href="'.htmlspecialchars($url).'" '.$target.'>'; - if($this->preferences["picto"] > '' and $this->preferences["picto"] != "vide.gif") { - $anchor.=sprintf('<img alt="%s" src="'.URL_IMG.'menus/'.$this->preferences["picto"].'" />', - $this->translate()->_('pictogramme pour %s', $this->preferences["libelle"])); + if($this->_picto > '' and $this->_picto != "vide.gif") { + $anchor.=sprintf('<img alt="%s" src="'.URL_IMG.'menus/'.$this->_picto.'" />', + $this->translate()->_('pictogramme pour %s', $this->_libelle)); } + $anchor.=$this->_preferences["libelle"].'</a>'; - $anchor.=$this->preferences["libelle"].'</a>'; return $anchor; } } diff --git a/library/ZendAfi/View/Helper/Menu/Menus.php b/library/ZendAfi/View/Helper/Menu/Menus.php new file mode 100644 index 00000000000..663e1226620 --- /dev/null +++ b/library/ZendAfi/View/Helper/Menu/Menus.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_View_Helper_Menu_Menus extends ZendAfi_View_Helper_BaseHelper { + protected $_ul_class = ''; + protected $_li_class = 'menu'; + protected $_menus = []; + + public function __construct($menus) { + parent::__construct(); + $this->_menus = $menus; + } + + public function getBoite() { + $html = '<ul class="'.$this->_ul_class.'">'; + + foreach($this->_menus as $id_menu => $entree) { + $li_class = Class_Systeme_ModulesMenu::isModuleAccueil($entree) + ? $this->_li_class.' boite' + : $this->_li_class; + + $html.= '<li class="'.$li_class.'">'; + $html.= $this->renderModule($id_menu, $entree); + $html.='</li>'; + } + + $html.='</ul>'; + return $html; + } + + + function renderModule($id_menu, $menu){ + $helper = ZendAfi_View_Helper_Menu_Base::getModuleHelperFromParams($id_menu, $menu); + $helper->setView($this->view); + return $helper->getBoite(); + } +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Menu/SousMenus.php b/library/ZendAfi/View/Helper/Menu/SousMenus.php new file mode 100644 index 00000000000..02480cf4bc3 --- /dev/null +++ b/library/ZendAfi/View/Helper/Menu/SousMenus.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_View_Helper_Menu_SousMenus extends ZendAfi_View_Helper_Menu_Menus { + protected $_ul_class = 'sous-menus'; + protected $_li_class = ''; +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/MenuHorizontal.php b/library/ZendAfi/View/Helper/MenuHorizontal.php index 0793c954730..ccfc035c616 100644 --- a/library/ZendAfi/View/Helper/MenuHorizontal.php +++ b/library/ZendAfi/View/Helper/MenuHorizontal.php @@ -35,41 +35,15 @@ class ZendAfi_View_Helper_MenuHorizontal extends ZendAfi_View_Helper_BaseHelper if(!count($menus)) return $this->retourErreur($this->translate()->_("Ce menu ne contient aucune entrée.")); + $helper = new ZendAfi_View_Helper_Menu_Menus($menus); + $helper->setView($this->view); + return '<div id="menu_horizontal">' .$this->tagEditMenu() - .$this->renderMenus($menus, '', 'menu') + .$helper->getBoite() // .$this->renderMenus($menus, '', 'menu') .'</div>'; } - - public function renderMenus($menus, $ul_class, $li_class='') { - $html = '<ul class="'.$ul_class.'">'; - - foreach($menus as $id_menu => $entree) { - if (Class_Systeme_ModulesMenu::isModuleAccueil($entree)) - $li_class .= ' boite'; - - $html.='<li class="'.trim($li_class).'">'; - $html.=$this->renderModule($id_menu, $entree); - - if(array_isset('sous_menus', $entree)) - $html .= $this->renderMenus($entree['sous_menus'], 'sous_menu'); - - $html.='</li>'; - } - - $html.='</ul>'; - return $html; - } - - - function renderModule($id_menu, $menu){ - $helper = ZendAfi_View_Helper_Menu_Base::getModuleHelperFromParams($id_menu, $menu); - $helper->setView($this->view); - return $helper->getBoite(); - } - - public function tagEditMenu() { return $this->view->tagAnchor($this->view->url(['module' => 'admin', 'controller' => 'profil', diff --git a/library/ZendAfi/View/Helper/ModuleAbstract.php b/library/ZendAfi/View/Helper/ModuleAbstract.php index 68e6b6715ef..e592da6556b 100644 --- a/library/ZendAfi/View/Helper/ModuleAbstract.php +++ b/library/ZendAfi/View/Helper/ModuleAbstract.php @@ -31,7 +31,6 @@ abstract class ZendAfi_View_Helper_ModuleAbstract extends ZendAfi_View_Helper_Ba public function __construct($id_module,$params) { parent::__construct(); $this->id_module = $id_module; - $this->type_module = $params["type_module"]; $this->preferences = $params["preferences"]; } -- GitLab