*/ class ControllerGuardServiceFactory implements FactoryInterface { /** * {@inheritDoc} * * @return \BjyAuthorize\Guard\Controller */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('BjyAuthorize\Config'); // print_r($config['guards']['BjyAuthorize\Guard\Controller']);exit(); $authorize = $serviceLocator->get('BjyAuthorize\Provider\Identity\ProviderInterface'); $roles = $authorize->getIdentityRoles(); $roleId = !empty($roles)?$roles[0]:'guest'; $roleId = 'guest'; $tableObj = new Tables('modules',$serviceLocator->get('Zend\Db\Adapter\Adapter')); $select = $tableObj->getTable()->getSql()->select(); $select->join('modules_role', 'modules_role.idModule = modules.id'); $select->where(array('modules_role.idRole' => $roleId)); $rows = $tableObj->getTable()->selectWith($select); $allModules = $tableObj->getTable()->select(); $myGuards[] = array('controller'=>'zfcuser','roles' => array('guest')); $myGuards[] = array('controller'=>'ZfcAdmin\Controller\AdminController','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\Index','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\Reservation','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\XML','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\appServices','roles' => array('guest')); $myGuards[] = array('controller'=>'Etudiant\Controller\Index','roles' => array('guest')); $myGuards[] = array('controller'=>'Etudiant\Controller\Api','roles' => array('guest')); $myGuards[] = array('controller'=>'Reservation\Controller\Api','roles' => array('guest')); //$myGuards[] = array('controller'=>'SwaggerModule\Controller\Documentation','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\TestErnest','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\Pms','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\Sig','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\Signature','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\Self','roles' => array('guest')); $myGuards[] = array('controller'=>'Application\Controller\Payment','roles' => array('guest')); $myGuards[] = array('controller'=>'Reservation\Controller\ApiRest','roles' => array('guest')); foreach ($allModules as $mod){ $myGuards[] = array( 'controller'=>$mod->controller, 'roles' => array($roleId) ); } ## my stats $userRole = 'guest'; $auth = $serviceLocator->get('zfcuser_auth_service'); if( $auth->hasIdentity() ){ $user = $auth->getIdentity(); $gestId = $user->getId(); $tableObjRoles = new Tables('user',$serviceLocator->get('Zend\Db\Adapter\Adapter')); $select = $tableObjRoles->getTable()->getSql()->select(); $select->join('user_role_linker', 'user_role_linker.user_id = user.user_id','role_id'); $select->where(array('user.user_id' => $gestId)); $userRoleResult = $tableObjRoles->getTable()->selectWith($select)->current(); if($userRoleResult) $userRole = $userRoleResult->role_id; } $tableObjMS = new Tables('mystats',$serviceLocator->get('Zend\Db\Adapter\Adapter')); $select = $tableObjMS->getTable()->getSql()->select(); $select->join('mystats_profile', 'mystats_profile.idMyStat = mystats.id',array('idMyStat')); $select->where(array('mystats_profile.idProfile' => $userRole,'mystats.deleted'=>0)); $rowsMS = $tableObjMS->getTable()->selectWith($select); $myStatSubMenu = array(); $userStats = array(); foreach($rowsMS as $r){ $myStatSubMenu[] = array('label'=>$r->nomStat, 'route' => 'zfcadmin/stats','action'=>'index','params' => array('id'=>$r->idMyStat)); $userStats[] = array('id'=>$r->id,'nomStat'=>$r->nomStat); } $_SESSION['USERSTATS'] = $userStats; /* $roleRoutes = array(); if($roleId == "superAdmin"){ foreach ($allModules as $mod){ $myGuards[] = array( 'controller'=>$mod->controller, 'roles' => array($roleId) ); } }else{ if($roleId != "guest" && $roleId != "user"){ foreach ($rows as $r){ if($r->droit == 'W'){ $myGuards[] = array( 'controller'=>$r->controller, 'roles' => array($roleId) ); $roleRoutes[] = "zfcadmin/".$r->route; }elseif($r->droit == 'R'){ $myGuards[] = array( 'controller'=>$r->controller, 'action'=>explode(',', $r->actionsR), 'roles' => array($roleId) ); $roleRoutes[] = "zfcadmin/".$r->route; } // } } } $roleRoutes[] = "zfcuser/logout"; //print_r($roleRoutes); $configGlobal = $serviceLocator->get('config'); $defaultNavigation = $configGlobal['navigation']['admin']; if($roleId != "superAdmin"){ //unset($defaultNavigation[1]); $i=0; foreach ($defaultNavigation as $nav) { $pages = $nav['pages']; if(isset($pages)){ $j = 0; foreach ($pages as $item) { if(!in_array($item['route'], $roleRoutes)){ unset($pages[$j]); //echo $item['route']."
"; } $j++; } $defaultNavigation[$i]['pages'] = $pages; } if(!in_array($nav['route'], $roleRoutes)){ unset($defaultNavigation[$i]); } $i++; } } //exit(); */ $configGlobal = $serviceLocator->get('config'); // WADIE VERSION $configTable = $serviceLocator->get('Reservation\Model\ConfigurationTable'); // DROITS $adminArray = array(); if(isset($_SESSION['USERDROIT'])){ // LISTES if($_SESSION['USERDROIT']['zfcadmin/liste'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/liste'] == 'R') $adminArray[] = array('label' => 'Listes', 'route' => 'zfcadmin/liste'); // STOCKS if($_SESSION['USERDROIT']['zfcadmin/stock'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/stock'] == 'R') $adminArray[] = array('label' => 'Stocks', 'route' => 'zfcadmin/stock'); // PLANNING if($_SESSION['USERDROIT']['zfcadmin/planning'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/planning'] == 'R') $adminArray[] = array('label' => 'Planning', 'route' => 'zfcadmin/planning'); // CAMPAGNES SUBMENU $campagneSubmenu = array(); // CANAUX if($_SESSION['USERDROIT']['zfcadmin/campagneCanaux'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneCanaux'] == 'R') $campagneSubmenu[] = array('label' => 'Canaux', 'route' => 'zfcadmin/campagneCanaux'); // TYPE LOGEMENT if($_SESSION['USERDROIT']['zfcadmin/campagneTypelogement'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneTypelogement'] == 'R') $campagneSubmenu[] = array('label' => 'Type logement', 'route' => 'zfcadmin/campagneTypelogement'); // TYPE LOGEMENT/CANAL if($_SESSION['USERDROIT']['zfcadmin/campagneTypelogementCanal'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneTypelogementCanal'] == 'R') $campagneSubmenu[] = array('label' => 'Type logement/canal', 'route' => 'zfcadmin/campagneTypelogementCanal'); // FORMULAIRE if($_SESSION['USERDROIT']['zfcadmin/campagneFormulaires'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneFormulaires'] == 'R') $campagneSubmenu[] = array('label' => 'Formulaire portail', 'route' => 'zfcadmin/campagneFormulaires'); // STOCKCS if($_SESSION['USERDROIT']['zfcadmin/campagneStockCS'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneStockCS'] == 'R') $campagneSubmenu[] = array('label' => 'Stocks Court-Séjour', 'route' => 'zfcadmin/campagneStockCS'); // DOCUMENTS if($_SESSION['USERDROIT']['zfcadmin/campagneDocument'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneDocument'] == 'R') $campagneSubmenu[] = array('label' => 'Documents', 'route' => 'zfcadmin/campagneDocument'); // DOCUMENTS RESIDENT if($_SESSION['USERDROIT']['zfcadmin/campagneDocumentResident'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneDocumentResident'] == 'R') $campagneSubmenu[] = array('label' => 'Documents usager', 'route' => 'zfcadmin/campagneDocumentResident'); // MODELES DOCUMENT CAMPAGNE if($_SESSION['USERDROIT']['zfcadmin/campagneModeleDocument'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneModeleDocument'] == 'R') $campagneSubmenu[] = array('label' => 'Modèles Documents', 'route' => 'zfcadmin/campagneModeleDocument'); // MAILS if($_SESSION['USERDROIT']['zfcadmin/campagneMailing'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneMailing'] == 'R') $campagneSubmenu[] = array('label' => 'Mails', 'route' => 'zfcadmin/campagneMailing'); // SMS if($_SESSION['USERDROIT']['zfcadmin/campagneSMS'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneSMS'] == 'R') $campagneSubmenu[] = array('label' => 'SMS', 'route' => 'zfcadmin/campagneSMS'); // INTER-CONTRAT if($_SESSION['USERDROIT']['zfcadmin/campagneIC'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneIC'] == 'R') $campagneSubmenu[] = array('label' => 'Inter-contrat', 'route' => 'zfcadmin/campagneIC'); // LOGOS if($_SESSION['USERDROIT']['zfcadmin/campagneLogos'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/campagneLogos'] == 'R') $campagneSubmenu[] = array('label' => 'Logos', 'route' => 'zfcadmin/campagneLogos'); // CAMPAGNE if($_SESSION['USERDROIT']['zfcadmin/tarif'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/tarif'] == 'R') $adminArray[] = array('label' => 'Campagnes', 'route' => 'zfcadmin/tarif', 'pages' => $campagneSubmenu); // AIGUILLAGES if($_SESSION['USERDROIT']['zfcadmin/formulaire'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/formulaire'] == 'R') $adminArray[] = array('label' => 'Formulaires aiguillage', 'route' => 'zfcadmin/formulaire'); // GENERAL SUBMENU $generalSubmenu = array(); // RESIDENCE if($_SESSION['USERDROIT']['zfcadmin/residence'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/residence'] == 'R') $generalSubmenu[] = array('label' => 'Résidences', 'route' => 'zfcadmin/residence'); // BATIMENTS if($_SESSION['USERDROIT']['zfcadmin/batiment'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/batiment'] == 'R') $generalSubmenu[] = array('label' => 'Bâtiments', 'route' => 'zfcadmin/batiment'); // TYPE LOGEMENT if($_SESSION['USERDROIT']['zfcadmin/typelogement'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/typelogement'] == 'R') $generalSubmenu[] = array('label' => 'Type logements', 'route' => 'zfcadmin/typelogement'); // LOGEMENTS if($_SESSION['USERDROIT']['zfcadmin/logements'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/logements'] == 'R') $generalSubmenu[] = array('label' => 'Logements', 'route' => 'zfcadmin/logements'); // STOCKSCS if($_SESSION['USERDROIT']['zfcadmin/stockCS'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/stockCS'] == 'R') $generalSubmenu[] = array('label' => 'Stocks Court-Séjour', 'route' => 'zfcadmin/stockCS'); // RPLS if($_SESSION['USERDROIT']['zfcadmin/RPLS'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/RPLS'] == 'R') $generalSubmenu[] = array('label' => 'RPLS', 'route' => 'zfcadmin/RPLS'); // CANAUX if($_SESSION['USERDROIT']['zfcadmin/canal'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/canal'] == 'R') $generalSubmenu[] = array('label' => 'Canaux', 'route' => 'zfcadmin/canal'); // DOCUMENTS if($_SESSION['USERDROIT']['zfcadmin/document'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/document'] == 'R') $generalSubmenu[] = array('label' => 'Documents', 'route' => 'zfcadmin/document'); // MAILS if($_SESSION['USERDROIT']['zfcadmin/mailing'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/mailing'] == 'R') $generalSubmenu[] = array('label' => 'Mails', 'route' => 'zfcadmin/mailing'); // DEMANDES if($_SESSION['USERDROIT']['zfcadmin/demandes'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/demandes'] == 'R') $generalSubmenu[] = array('label' => 'Formulaires', 'route' => 'zfcadmin/demandes'); // COLIS if($_SESSION['USERDROIT']['zfcadmin/colis'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/colis'] == 'R') $generalSubmenu[] = array('label' => $configTable->getConfig(1)->colisval, 'route' => 'zfcadmin/colis'); // MULTISUIVIS if($_SESSION['USERDROIT']['zfcadmin/multisuivis'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/multisuivis'] == 'R') $generalSubmenu[] = array('label' => 'Multisuivis', 'route' => 'zfcadmin/multisuivis'); // SMS if($_SESSION['USERDROIT']['zfcadmin/sms'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/sms'] == 'R') $generalSubmenu[] = array('label' => 'SMS', 'route' => 'zfcadmin/sms'); // DUREE GENARAL if($_SESSION['USERDROIT']['zfcadmin/dureegeneral'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/dureegeneral'] == 'R') $generalSubmenu[] = array('label' => 'Durée général', 'route' => 'zfcadmin/dureegeneral'); // FINANCIER if($_SESSION['USERDROIT']['zfcadmin/financier'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/financier'] == 'R') $generalSubmenu[] = array('label' => 'Financier', 'route' => 'zfcadmin/financier'); // CATALOGUE if($_SESSION['USERDROIT']['zfcadmin/catalogue'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/catalogue'] == 'R') $generalSubmenu[] = array('label' => 'Catalogues', 'route' => 'zfcadmin/catalogue'); // PUSH if($_SESSION['USERDROIT']['zfcadmin/push'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/push'] == 'R') $generalSubmenu[] = array('label' => 'Push', 'route' => 'zfcadmin/push'); // GENERAL if($_SESSION['USERDROIT']['zfcadmin/general'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/general'] == 'R') $adminArray[] = array('label' => 'Général', 'route' => 'zfcadmin/general', 'pages' => $generalSubmenu); // // SOUS MENU FACTURATION $facturationSubmenu = array(); // BROUILLARD if($_SESSION['USERDROIT']['zfcadmin/brouillard'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/brouillard'] == 'R') $facturationSubmenu[] = array('label' => 'Brouillard', 'route' => 'zfcadmin/brouillard'); // FACTURATION if($_SESSION['USERDROIT']['zfcadmin/facturation'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/facturation'] == 'R') $adminArray[] = array('label' => 'Facturation', 'route' => 'zfcadmin/facturation','pages' => $facturationSubmenu); // GESTION SUBMENU $gestionSubmenu = array(); // UTILISATEUR if($_SESSION['USERDROIT']['zfcadmin/user'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/user'] == 'R') $gestionSubmenu[] = array('label' => 'Utilisateurs', 'route' => 'zfcadmin/user'); // PROFIL if($_SESSION['USERDROIT']['zfcadmin/droit'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/droit'] == 'R') $gestionSubmenu[] = array('label' => 'Profil', 'route' => 'zfcadmin/droit'); // GESTION if($_SESSION['USERDROIT']['zfcadmin/gestionacces'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/gestionacces'] == 'R') $adminArray[] = array('label' => 'Gestion des accès', 'route' => 'zfcadmin/gestionacces', 'pages' => $gestionSubmenu); // STATS SUBMENU $statsSubmenu = array(); // Taux d\'occupation if($_SESSION['USERDROIT']['zfcadmin/occupation'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/occupation'] == 'R') $statsSubmenu[] = array('label' => 'Taux d\'occupation', 'route' => 'zfcadmin/occupation'); // Impayés if($_SESSION['USERDROIT']['zfcadmin/statuts'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/statuts'] == 'R') $statsSubmenu[] = array('label' => 'Evolution des demandes', 'route' => 'zfcadmin/statuts'); // CA if($_SESSION['USERDROIT']['zfcadmin/ca'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/ca'] == 'R') $statsSubmenu[] = array('label' => 'CA', 'route' => 'zfcadmin/ca'); // Population if($_SESSION['USERDROIT']['zfcadmin/population'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/population'] == 'R') $statsSubmenu[] = array('label' => 'Population', 'route' => 'zfcadmin/population'); // Impayés if($_SESSION['USERDROIT']['zfcadmin/impaye'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/impaye'] == 'R') $statsSubmenu[] = array('label' => 'Impayés', 'route' => 'zfcadmin/impaye'); // Ressources if($_SESSION['USERDROIT']['zfcadmin/ressources'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/ressources'] == 'R') $statsSubmenu[] = array('label' => 'Plafonds ressources', 'route' => 'zfcadmin/ressources'); if(!empty($myStatSubMenu)){ foreach($myStatSubMenu as $ms){ $statsSubmenu[] = $ms; } } // STATS if($_SESSION['USERDROIT']['zfcadmin/stats'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/stats'] == 'R') $adminArray[] = array('label' => 'Statistiques', 'route' => 'zfcadmin/stats', 'pages' => $statsSubmenu); // PORTAIL RESIDENTS if($_SESSION['USERDROIT']['zfcadmin/etudianthome'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/etudianthome'] == 'R') $adminArray[] = array('label' => 'Portail résidents', 'route' => 'zfcadmin/etudianthome'); // SYSTEME if($_SESSION['USERDROIT']['zfcadmin/configuration'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/configuration'] == 'R') $adminArray[] = array('label' => 'Système', 'route' => 'zfcadmin/configuration'); // ACCES PLATFORMES if($_SESSION['USERDROIT']['zfcadmin/portail'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/portail'] == 'R') $adminArray[] = array('label' => 'Accès plateformes', 'route' => 'zfcadmin/portail'); // HISTORIQUE if($_SESSION['USERDROIT']['zfcadmin/logs'] == 'W' || $_SESSION['USERDROIT']['zfcadmin/logs'] == 'R') $adminArray[] = array('label' => 'Historique', 'route' => 'zfcadmin/logs'); // LOGOUT $adminArray[] = array('label' => 'Logout', 'route' => 'zfcuser/logout'); } $configGlobal['navigation']['admin'] = $adminArray; //$serviceLocator->set('Config',$configGlobal); $serviceLocator->setAllowOverride(true); // service keys are case insensitive // just remember that $this->config should contain the whole config $serviceLocator->setService('Config', $configGlobal); $serviceLocator->setAllowOverride(false); //print_r($serviceLocator->get('config')); if(!empty($myGuards)){ return new Controller($myGuards, $serviceLocator); } return new Controller($config['guards']['BjyAuthorize\Guard\Controller'], $serviceLocator); } }