webservice/library/Application/Controller/Plugin/Menu.php
2016-06-02 10:53:17 +02:00

40 lines
1.2 KiB
PHP

<?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);
// --- Secure demo mode
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$user = $auth->getIdentity();
if ($user->idClient != 1) {
$toSecure = $container->findOneBy('Label', "Démonstration");
$container->removePage($toSecure);
}
}
$view->navigation($container);
}
}
}