2012-12-26 10:36:47 +00:00

83 lines
2.4 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();
if ( $layout->isEnabled() && $request->getControllerName()!='print' )
{
$controller = $request->getControllerName();
$action = $request->getActionName();
//Override SIRET to complete with zero by left
$siret = $request->getParam('siret');
if ( intval($siret)>100 ) {
$request->setParam('siret', str_pad($siret, 9, '0', STR_PAD_LEFT));
}
//Génération du menu
require_once 'Scores/Menu.php';
$computeMenu = new Menu($request->getParams());
$menu = $computeMenu->getMenu();
$view = $layout->getView();
$view->navigation($menu);
//Génération identifiant Menu
$view->menuId = $computeMenu->getIdMenu($controller, $action);
//Test if the user has the right to access the page
$hasPerm = true;
$permPage = $computeMenu->getPagePermission($controller, $action);
if ( !empty($permPage) ) {
$hasPerm = false;
if (is_array($permPage)){
$list = $permPage;
} else if (is_string($permPage)){
$list = (array)$permPage;
}
$user = new Scores_Utilisateur();
foreach($list as $permission){
if ($user->checkPerm($permission)){
$hasPerm = true;
break;
}
}
}
if ( !$hasPerm ) {
$request->setModuleName('default')
->setControllerName('error')
->setActionName('perms');
} else {
//Gestion affichage Lien Print / PDF / XML
require_once 'Scores/PagePrint.php';
$page = new PagePrint($controller, $action);
if ($page->exportable('print')){
$view->print = $page->filename('print', $request->getParams());
}
if ($page->exportable('pdf')){
$view->pdf = $page->filename('pdf', $request->getParams());
}
if ($page->exportable('xml')){
$view->xml = $page->filename('xml', $request->getParams());
}
}
}
//Icone d'aide
if ($layout->isEnabled() && $request->getControllerName()!='recherche')
{
//$view->aide = true;
}
}
}