getApplication()->getEventManager(); $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'selectLayoutBasedOnRoute')); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $sm = $e->getApplication()->getServiceManager(); $router = $sm->get('router'); $request = $sm->get('request'); $matchedRoute = $router->match($request); $params = $controller = $action = $route = null; if ($matchedRoute) { $params = $matchedRoute->getParams(); $controller = $params['controller']; $action = $params['action']; $route = $matchedRoute->getMatchedRouteName(); } $module_array = explode('\\', $controller); $module = array_pop($module_array); //roles $authorize = $sm->get('BjyAuthorize\Provider\Identity\ProviderInterface'); $roles = $authorize->getIdentityRoles(); $isAdmin = false; if (in_array('admin', $roles)) { $isAdmin = true; } //message defilant $etudiantHomeTale = $sm->get('Reservation\Model\EtudianthomeTable'); $lang_session = new Container('lang'); $lang = $lang_session->lang; if (!$lang) { $lang = $sm->get('translator')->getLocale(); } $locsess = new Container('loc'); $idResidence = 0; if ($locsess && $locsess->loc) { $idResidence = $this->getResidenceDuLocataire($locsess->loc->id, $sm); } $marquee = $etudiantHomeTale->fetchAllPublished(1, $lang, $idResidence); $demandesModelesTable = $sm->get('Reservation\Model\DemandesModelesTable'); $demandesActif = $demandesModelesTable->anyDemandesModeleActif(); $configTable = $sm->get('Reservation\Model\ConfigurationTable'); $config = $configTable->getConfig(1); $tableCG = new Tables('config_global', $sm->get('Zend\Db\Adapter\Adapter')); $configGlobal = $tableCG->getTable()->select(array('param' => 'RESALLE'))->current(); ## vérification si première connexion, on demande le changement de mot de passe //echo var_dump($locsess->loginCWR);exit(); $request = $sm->get('request'); $matchedRoute = $router->match($request); if ($matchedRoute) { $params = $matchedRoute->getParams(); $nameSpace = $params['__NAMESPACE__']; $controller = $params['controller']; $action = $params['action']; if($nameSpace == 'Etudiant\Controller' && $controller == 'Index') { $controller = "Etudiant\Controller\Index"; } if($locsess && $locsess->loc && $locsess->loginCWR && $controller == "Etudiant\Controller\Index") { if($locsess->loc->isReset == 1) { $redir = true; if (($controller == "Etudiant\Controller\Index" && $action == "edit")) { $redir = false; } if ($redir) { $locsess->resetPassword = true; $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function ($e) { $controller = $e->getTarget(); $controller->plugin('redirect')->toRoute('edit'); }, 100); } } } } //// $e->getViewModel()->setVariables( array( 'CURRENT_MODULE_NAME' => $module, 'CURRENT_CONTROLLER_NAME' => $controller, 'CURRENT_ACTION_NAME' => $action, 'CURRENT_ROUTE_NAME' => $route, 'IS_ADMIN' => $isAdmin, 'marquee' => $marquee, 'demandesActif' => $demandesActif, 'config' => $config, 'configGlobal' => $configGlobal, ) ); } private function getResidenceDuLocataire($idLocataire, $sm) { $idResidence = 0; $getResaAppTable = $sm->get('Reservation\Model\ResaTable'); $getResidencesTable = $sm->get('Reservation\Model\ResidencesTable'); $getLogementTable = $sm->get('Reservation\Model\LogementTable'); $getTypelogementBOTable = $sm->get('Reservation\Model\TypelogementTable'); $resa = $getResaAppTable->getResaBy(array('idLocataire' => $idLocataire))->current(); if ($resa) { if ($resa->codeSite) { $resid = $getResidencesTable->getResidenceBy(array('idPMS' => $resa->codeSite)); if ($resid) { $idResidence = $resid->id; } } elseif ($resa->idLogement) { $resid = $getLogementTable->getResidenceDeLogement($resa->idLogement); if ($resid) { $idResidence = $resid->idResidence; } } elseif ($resa->idTypeLogementAttribue) { $residenceDuType = $getTypelogementBOTable->getResidenceDuTypeLogement($resa->idTypeLogementAttribue); if ($residenceDuType) { $idResidence = $residenceDuType->idResidence; } } } return $idResidence; } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } public function getServiceConfig() { return array( 'factories' => array( 'Etudiant\Model\EtudiantTable' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $table = new StickyNotesTable($dbAdapter); return $table; }, 'Etudiant\Model\LocataireTable' => function ($sm) { $tableGateway = $sm->get('LocataireTableGateway'); $table = new LocataireTable($tableGateway); return $table; }, 'Etudiant\Model\ResaEtudTable' => function ($sm) { $tableGateway = $sm->get('ResaEtudTableGateway'); $table = new ResaEtudTable($tableGateway); return $table; }, 'ResaEtudTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new ResaEtud()); return new TableGateway('reservations', $dbAdapter, null, $resultSetPrototype); }, 'Etudiant\Model\PaysTable' => function ($sm) { $tableGateway = $sm->get('PaysTableGateway'); $table = new PaysTable($tableGateway); return $table; }, 'PaysTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Pays()); return new TableGateway('pays', $dbAdapter, null, $resultSetPrototype); }, 'Etudiant\Model\ComptesTable' => function ($sm) { $tableGateway = $sm->get('ComptesTableGateway'); $table = new ComptesTable($tableGateway); return $table; }, 'ComptesTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Comptes()); return new TableGateway('comptes', $dbAdapter, null, $resultSetPrototype); }, 'Etudiant\Model\PaiementTable' => function ($sm) { $tableGateway = $sm->get('PaiementTableGateway'); $table = new PaiementTable($tableGateway); return $table; }, 'PaiementTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Paiement()); return new TableGateway('paiements', $dbAdapter, null, $resultSetPrototype); }, 'Etudiant\Model\ErrorOgoneTable' => function ($sm) { $tableGateway = $sm->get('ErrorOgoneTableGateway'); $table = new ErrorOgoneTable($tableGateway); return $table; }, 'ErrorOgoneTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new ErrorOgone()); return new TableGateway('erreur_ogone', $dbAdapter, null, $resultSetPrototype); }, 'Reservation\Model\HistoriquePushTable' => function ($sm) { $tableGateway = $sm->get('HistoriquePushTableGateway'); $table = new HistoriquePushTable($tableGateway); return $table; }, 'HistoriquePushTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new HistoriquePush()); return new TableGateway('historiquePush', $dbAdapter, null, $resultSetPrototype); }, 'Reservation\Model\LocPushTable' => function ($sm) { $tableGateway = $sm->get('LocPushTableGateway'); $table = new LocPushTable($tableGateway); return $table; }, 'LocPushTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new LocPush()); return new TableGateway('locPush', $dbAdapter, null, $resultSetPrototype); }, 'LocataireTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Locataire()); return new TableGateway('locataires', $dbAdapter, null, $resultSetPrototype); }, ), ); } public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } public function selectLayoutBasedOnRoute(MvcEvent $e) { $app = $e->getParam('application'); $sm = $app->getServiceManager(); $config = $sm->get('config'); $auth = $sm->get('zfcuser_auth_service'); $match = $e->getRouteMatch(); $routeName = $e->getRouteMatch()->getMatchedRouteName(); $resaRoute = explode("/", $routeName); $controller = $e->getTarget(); /*if (!$match instanceof RouteMatch || 0 !== strpos($match->getMatchedRouteName(), 'zfcuser/login') || $controller->getEvent()->getResult()->terminate() ) { return; }*/ // User is authenticated if (!$auth->hasIdentity()) { if (in_array("home", $resaRoute) || in_array("zfcuser", $resaRoute) || in_array("reservation", $resaRoute)) { return; } else { $controller->layout('layout/layout-etudiant'); } } else { if (!in_array("zfcadmin", $resaRoute)) { if (in_array("home", $resaRoute) || in_array("zfcuser", $resaRoute) || in_array("reservation", $resaRoute)) { return; } else { $controller->layout('layout/layout-etudiant'); } } else { $controller->layout('layout/admin'); } } /*if (0 !== strpos($match->getMatchedRouteName(), 'zfcadmin')){ $controller->layout('layout/layout-etudiant'); }else{ $controller->layout('layout/admin'); }*/ } }