Menu : gestion des paramètres et du mode actif

This commit is contained in:
Michael RICOIS 2016-06-07 10:14:53 +02:00
parent 14995f61c4
commit 2f2ed3e5f3

View File

@ -1,6 +1,12 @@
<?php
class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
{
/**
* Menu Container
* @var Zend_Navigation_Container
*/
protected $container;
/**
* Créer le menu en fonction des besoins et des paramètres en entrée
* @param Zend_Controller_Request_Abstract $request
@ -48,8 +54,9 @@ class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
$view->MenuAdvanced = true;
$view->MenuLabel = 'Administration';
$config = include APPLICATION_PATH . '/configs/menu.admin.php';
$container = new Zend_Navigation($config);
$view->navigation($container);
$this->container = new Zend_Navigation($config);
$this->setParentActive();
$view->navigation($this->container);
$view->headLink()
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
$view->headScript()
@ -60,8 +67,9 @@ class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
$view->MenuAdvanced = true;
$view->MenuLabel = 'Recherche';
$config = include APPLICATION_PATH . '/configs/menu.search.php';
$container = new Zend_Navigation($config);
$view->navigation($container);
$this->container = new Zend_Navigation($config);
$this->setParentActive();
$view->navigation($this->container);
$view->headLink()
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
$view->headScript()
@ -72,8 +80,9 @@ class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
$view->MenuAdvanced = true;
$view->MenuLabel = 'Mon compte';
$config = include APPLICATION_PATH . '/configs/menu.user.php';
$container = new Zend_Navigation($config);
$view->navigation($container);
$this->container = new Zend_Navigation($config);
$this->setParentActive();
$view->navigation($this->container);
$view->headLink()
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
$view->headScript()
@ -84,29 +93,20 @@ class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
$view->MenuAdvanced = true;
$view->MenuLabel = 'Informations légales';
$config = include APPLICATION_PATH . '/configs/menu.legal.php';
$container = new Zend_Navigation($config);
if ($container->hasPages()) {
foreach($container->getPages() as $head) {
if ($head->hasChildren()) {
foreach($head->getPages() as $page) {
if ($page->isActive()) {
$head->setActive();
}
// @todo : Set parameters filters by plugin ProxId "cid", "ctype"
$page->setParam('siret', $request->getParam('siret'));
$page->setParam('id', $request->getParam('id'));
}
}
}
}
$view->navigation($container);
$this->container = new Zend_Navigation($config);
$this->setParentActive();
$this->setPageParams($request);
$view->navigation($this->container);
$view->headLink()
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
$view->headScript()
->appendFile('/libs/metisMenu/metisMenu.min.js', 'text/javascript');
break;
default:
// Menu Default
// --- Affichage page error
// --- Affichage page 404
// --- Override SIRET to complete with zero by left
$siret = $request->getParam('siret');
if ( intval($siret)>100 ) {
@ -164,13 +164,33 @@ class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
Zend_Registry::get('firebug')->info('PLUGIN MENU - END');
}
protected function setParentActive($page)
{
protected function setParentActive()
{
if ($this->container->hasPages()) {
foreach($this->container->getPages() as $head) {
if ($head->hasChildren()) {
foreach($head->getPages() as $page) {
if ($page->isActive()) {
$head->setActive();
}
}
}
}
}
}
protected function setPageParams($pages)
protected function setPageParams($request)
{
if ($this->container->hasPages()) {
foreach($this->container->getPages() as $head) {
if ($head->hasChildren()) {
foreach($head->getPages() as $page) {
// @todo : Set parameters filters by plugin ProxId "cid", "ctype"
$page->setParam('siret', $request->getParam('siret'));
$page->setParam('id', $request->getParam('id'));
}
}
}
}
}
}