protected function getPages(ServiceLocatorInterface $serviceLocatorInterface) { if (null === $this->pages) { $dbAdapter = $serviceLocatorInterface->get('Sundew\\Db\\Adapter'); $menuTable = new MenuDataAccess($dbAdapter); $userId = 0; $authService = $serviceLocatorInterface->get('AuthService'); if ($authService->hasIdentity()) { $userId = $authService->getIdentity()->userId; } $cache_ns = 'menu_cache_' . $userId; $menuList = $menuTable->getCache()->getItem($cache_ns); if (!$menuList) { $userRoleDA = new UserRoleDataAccess($dbAdapter); $roles = array(); foreach ($userRoleDA->grantRoles($userId) as $role) { array_push($roles, (int) $role->roleId); } $menuList = $menuTable->getMenuList(null, $roles); $menuTable->getCache()->setItem($cache_ns, $menuList); } $configuration['navigation'][$this->getName()] = $menuList; if (!isset($configuration['navigation'])) { throw new InvalidArgumentException('Could not find navigation configuration key'); } if (!isset($configuration['navigation'][$this->getName()])) { throw new InvalidArgumentException(sprintf('Failed to find a navigation container by the name "%s"', $this->getName())); } $pages = $this->getPagesFromConfig($configuration['navigation'][$this->getName()]); $this->pages = $this->preparePages($serviceLocatorInterface, $pages); } return $this->pages; }
public function getServiceConfig() { if ($this->serviceConfig == null) { $this->serviceConfig = array('factories' => array('Sundew\\AuthStorage' => function ($sm) { return new SundewAuthStorage('ceo_auth'); }, 'AuthService' => function ($sm) { $dbAdapter = $sm->get('Sundew\\Db\\Adapter'); $authService = new AuthenticationService(); $authService->setAdapter(new CredentialTreatmentAdapter($dbAdapter, 'tbl_user', 'username', 'password', 'MD5(?) AND status="A"')); $authService->setStorage($sm->get('Sundew\\AuthStorage')); return $authService; }, 'RouteData' => function ($sm) { $dbAdapter = $sm->get('Sundew\\Db\\Adapter'); $routeDataAccess = new RouteDataAccess($dbAdapter); $authService = $sm->get('AuthService'); if ($authService->hasIdentity()) { $userId = $authService->getIdentity()->userId; $cache_ns = 'route_cache_' . $userId; $routeData = $routeDataAccess->getCache()->getItem($cache_ns); if (!$routeData) { $userRoleDA = new UserRoleDataAccess($dbAdapter); $roles = array(); $userRoles = $userRoleDA->grantRoles($userId); if (!$userRoles) { return array(); } foreach ($userRoles as $role) { array_push($roles, (int) $role->roleId); } $routeData = $routeDataAccess->getRouteData($roles); if (!$routeData) { return array(); } $routeDataAccess->getCache()->setItem($cache_ns, $routeData->toArray()); } return $routeData; } return array(); }, 'AppErrorHandling' => function ($sm) { $authStorage = $sm->get('Sundew\\AuthStorage'); $user = array(); if (!$authStorage->isEmpty()) { $user = $authStorage->read(); } $filename = 'Error' . date('Ymd') . '.log'; $service = new SundewLogger($filename, $user); return $service; })); } return $this->serviceConfig; }