51 lines
1.6 KiB
PHP
Raw Normal View History

<?php
class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
{
/**
* Créer le menu en fonction des besoins et des paramètres en entrée
* @param Zend_Controller_Request_Abstract $request
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$layout = Zend_Layout::getMVCInstance();
$controller = $request->getControllerName();
$action = $request->getActionName();
$activateLayout = true;
if ( $controller == 'user' && in_array($action, array('login', 'logout')) ) {
$activateLayout = false;
}
if ( $layout->isEnabled() && $activateLayout ) {
$view = $layout->getView();
$config = include APPLICATION_PATH . '/configs/menu.config.php';
$container = new Zend_Navigation($config);
//Add services
$pagesService = array();
if ( count($view->WsServices)>0 ) {
foreach ( $view->WsServices as $service => $params ) {
$service = array(
'label'=> $params['name'],
'controller' => 'documentation',
'action' => 'service',
'params' => array(
'name' => $service,
'type' => $params['type'],
),
);
$pagesService[] = $service;
}
}
$found = $container->findOneByLabel("Documentation");
$found->addPages($pagesService);
$view->navigation($container);
}
}
}