public function init($oMvcEvent) { $this->setServiceLocator($oMvcEvent->getApplication()->getServiceManager()); if ($this->getServiceLocator()->has('AuthService')) { $this->_oAuthPlugin = $this->getServiceLocator()->get('AuthService'); } $this->_oAcl = new Acl(); $oAclSessionContainer = new \User\Model\AclSessionContainer(); if ($oAclSessionContainer->getIsInit()) { $aResource = $oAclSessionContainer->getResource(); $aUserRole = $oAclSessionContainer->getUserRole(); $aMenu = $oAclSessionContainer->getMenu(); } else { $aResource = $this->getNavigationResourceTable()->getAll(); $aUserRole = $this->getUserRoleTable()->getAll(); $aMenu = $this->getNavigationMenuTable()->getAll(); if (is_array($aMenu) && count($aMenu)) { foreach ($aMenu as $oMenu) { $oMenu->user_role_id = $this->getNavigationPrivilegeUserRoleTable()->getAll(array('navigation_privilege_id' => $oMenu->navigation_privilege_id)); } } $oAclSessionContainer->setResource($aResource); $oAclSessionContainer->setUserRole($aUserRole); $oAclSessionContainer->setMenu($aMenu); $oAclSessionContainer->setIsInit(1); } if (is_array($aResource) && count($aResource)) { foreach ($aResource as $oResource) { if (!$this->_oAcl->hasResource($oResource->value)) { $this->_oAcl->addResource(new Resource($oResource->value)); } } } if (is_array($aUserRole) && count($aUserRole)) { foreach ($aUserRole as $oUserRole) { if (!$this->_oAcl->hasRole($oUserRole->role_name)) { $this->_oAcl->addRole(new Role($oUserRole->role_name)); } } } if (is_array($aMenu) && count($aMenu)) { foreach ($aMenu as $oMenu) { if (is_array($oMenu->user_role_id) && count($oMenu->user_role_id)) { $aUserRole = array(); foreach ($oMenu->user_role_id as $oUserRole) { array_push($aUserRole, $oUserRole->user_role_name); } $this->_oAcl->allow($aUserRole, $oMenu->navigation_resource_name, $oMenu->navigation_privilege_name); $sUniqueKey = md5($oMenu->navigation_module_name . $oMenu->navigation_controller_name . $oMenu->navigation_action_name . $this->getSiteHref($oMenu->label_name) . 'html'); if ($sUniqueKey) { $this->_oAcl->allow($aUserRole, $oMenu->navigation_resource_name, $oMenu->navigation_privilege_name . $sUniqueKey); } } } } if (!$this->_oAcl->hasResource('application')) { $this->_oAcl->addResource(new Resource('application')); } if (!$this->_oAcl->hasResource('user')) { $this->_oAcl->addResource(new Resource('user')); } $this->_oAcl->deny(); //$this->_oAcl->allow(array('guest', 'admin'), 'application', 'index:index'); //$this->_oAcl->allow(array('guest', 'admin'), 'application', 'navigation:menu'); $this->_oAcl->allow(array('guest'), 'user', 'index:login'); $this->_oAcl->allow(array('admin'), 'user', 'index:logout'); $sControllerClassName = get_class($oMvcEvent->getTarget()); $sModule = strtolower(substr($sControllerClassName, 0, strpos($sControllerClassName, '\\'))); $sController = strtolower($oMvcEvent->getRouteMatch()->getParam('__CONTROLLER__')); $sAction = strtolower($oMvcEvent->getRouteMatch()->getParam('action')); $sMenu = strtolower($oMvcEvent->getRouteMatch()->getParam('menu')); $sSubmenu = strtolower($oMvcEvent->getRouteMatch()->getParam('submenu')); $sSubsubmenu = strtolower($oMvcEvent->getRouteMatch()->getParam('subsubmenu')); $sFormat = strtolower($oMvcEvent->getRouteMatch()->getParam('format')); if ($sMenu && $sModule && $sController && $sAction) { $sLabel = $this->getSiteHref($sMenu); if ($sSubmenu) { $sLabel = $this->getSiteHref($sSubmenu); if ($sSubsubmenu) { $sLabel = $this->getSiteHref($sSubsubmenu); } } $sUniqueKey = md5($sModule . $sController . $sAction . $sLabel . $sFormat); if (!$this->_oAcl->isAllowed($this->getRole(), $sModule, $sController . ':' . $sAction . $sUniqueKey)) { $sUrl = $oMvcEvent->getRouter()->assemble(array('action' => 'login'), array('name' => 'user_index/user_index_process')); if ($this->getRole() === 'admin') { $sUrl = $oMvcEvent->getRouter()->assemble(array('action' => 'index'), array('name' => 'home')); } $oResponse = $oMvcEvent->getResponse(); $oResponse->getHeaders()->addHeaderLine('Location', $sUrl); $oResponse->setStatusCode(302); $oResponse->sendHeaders(); $oMvcEvent->stopPropagation(); } if ($this->getServiceLocator()->has('VNavigationMenuTableService')) { $oMenu = $this->getServiceLocator()->get('VNavigationMenuTableService')->getRow(array('navigation_module_name' => $sModule, 'navigation_controller_name' => $sController, 'navigation_action_name' => $sAction, 'unique_key' => $sUniqueKey)); } } else { if ($sModule && $sController && $sAction) { if (!$this->_oAcl->isAllowed($this->getRole(), $sModule, $sController . ':' . $sAction)) { $sUrl = $oMvcEvent->getRouter()->assemble(array('action' => 'login'), array('name' => 'user_index/user_index_process')); if ($this->getRole() === 'admin') { $sUrl = $oMvcEvent->getRouter()->assemble(array('action' => 'index'), array('name' => 'home')); } $oResponse = $oMvcEvent->getResponse(); $oResponse->getHeaders()->addHeaderLine('Location', $sUrl); $oResponse->setStatusCode(302); $oResponse->sendHeaders(); $oMvcEvent->stopPropagation(); } if ($this->getServiceLocator()->has('VNavigationMenuTableService')) { $oMenu = $this->getServiceLocator()->get('VNavigationMenuTableService')->getRow(array('navigation_module_name' => $sModule, 'navigation_controller_name' => $sController, 'navigation_action_name' => $sAction)); } } } if ($oMenu instanceof \Application\Model\Entity\VNavigationMenu) { if ($this->getServiceLocator()->has('SiteSeoSiteSeoMetaKeywordsTableService') && $this->getServiceLocator()->has('SiteSeoMetaKeywordsTableService') && $this->getServiceLocator()->has('SiteSeoTableService')) { $sHeadTitle = ''; $sMetaDescription = ''; $sMetaKeywords = ''; $aMetaKeywords = array(); $sMetaRobots = 'index, follow'; if ($oMenu->site_seo_id) { $oSiteSeo = $this->getServiceLocator()->get('SiteSeoTableService')->getRow(array('id' => $oMenu->site_seo_id)); if ($oSiteSeo->head_title) { $sHeadTitle = $oSiteSeo->head_title; } if ($oSiteSeo->meta_description) { $sMetaDescription = $oSiteSeo->meta_description; } if ($oSiteSeo->site_seo_robots_name) { $sMetaRobots = $oSiteSeo->site_seo_robots_name; } $oMenu->site_seo_meta_keywords_id = $this->getServiceLocator()->get('SiteSeoSiteSeoMetaKeywordsTableService')->getAll(array('site_seo_id' => $oMenu->site_seo_id, 'active' => 1)); if (count($oMenu->site_seo_meta_keywords_id)) { foreach ($oMenu->site_seo_meta_keywords_id as $oValue) { array_push($aMetaKeywords, $oValue->site_seo_meta_keywords_name); } } } $oDefaultMetaKeywords = $this->getServiceLocator()->get('SiteSeoMetaKeywordsTableService')->getAll(array('primary' => 1, 'active' => 1)); if (count($oDefaultMetaKeywords)) { foreach ($oDefaultMetaKeywords as $oValue) { array_push($aMetaKeywords, $oValue->value); } } $aMetaKeywords = array_unique($aMetaKeywords); $nMetaKeywordsCount = count($aMetaKeywords); $nIdx = 1; if ($nMetaKeywordsCount) { foreach ($aMetaKeywords as $sValue) { if ($nMetaKeywordsCount == $nIdx) { $sMetaKeywords .= $sValue; } else { $sMetaKeywords .= $sValue . ','; } $nIdx++; } } $oRenderer = $this->getServiceLocator()->get('Zend\\View\\Renderer\\PhpRenderer'); $oRenderer->headTitle($sHeadTitle); $oRenderer->headMeta()->appendName('description', $sMetaDescription); $oRenderer->headMeta()->appendName('keywords', $sMetaKeywords); $oRenderer->headMeta()->appendName('robots', $sMetaRobots); } if ($oMenu->navigation_layout_name) { $oController = $oMvcEvent->getTarget(); $oController->layout($oMenu->navigation_layout_name); } } }
public function menuAction() { $oAclSessionContainer = new \User\Model\AclSessionContainer(); $oAclSessionContainer->setIsInit(0); $this->repairNavigationMenu(true, true, true); $oMenuItemSettingsForm = $this->getServiceLocator()->get('MenuItemSettingsFormService'); $oChangeMenuConfigurationForm = $this->getServiceLocator()->get('ChangeMenuConfigurationFormService'); $oAddNewNavigationMenuForm = $this->getServiceLocator()->get('NavigationMenuFormService'); $oEditNavigationMenuForm = $this->getServiceLocator()->get('EditNavigationMenuFormService'); $oAddNewNavigationMenuConfigurationForm = $this->getServiceLocator()->get('NavigationMenuConfigurationFormService'); $oEditNavigationMenuConfigurationForm = $this->getServiceLocator()->get('EditNavigationMenuConfigurationFormService'); $oAddNewSiteSeoMetaKeywordsForm = $this->getServiceLocator()->get('SiteSeoMetaKeywordsFormService'); $oEditSiteSeoMetaKeywordsForm = $this->getServiceLocator()->get('EditSiteSeoMetaKeywordsFormService'); $aNavigationMenu = array(); $nNavigationMenuConfigurationId = null; $nNavigationModuleId = null; $aSort = array('sort_column' => 'order', 'sort_method' => 'asc'); if ($this->getRequest()->isPost() && $this->params()->fromPost('form_name') === 'change_menu_configuration') { $oChangeMenuConfigurationForm->setData($this->getRequest()->getPost()); if ($oChangeMenuConfigurationForm->isValid()) { $nNavigationMenuConfigurationId = (int) $this->params()->fromPost('navigation_menu_configuration_id'); $nNavigationModuleId = (int) $this->params()->fromPost('navigation_module_id'); } } else { $nNavigationMenuConfigurationId = $this->getNavigationMenuConfigurationTable()->getRow()->id; $oChangeMenuConfigurationForm->setData(array('navigation_menu_configuration_id' => $nNavigationMenuConfigurationId)); } if ($nNavigationMenuConfigurationId && $nNavigationModuleId) { $aMenu = $this->getNavigationMenuTable()->getAll(array('navigation_menu_configuration_id' => $nNavigationMenuConfigurationId, 'navigation_level_id' => 1, 'navigation_module_id' => $nNavigationModuleId, 'sort' => $aSort)); } else { if ($nNavigationMenuConfigurationId && !$nNavigationModuleId) { $aMenu = $this->getNavigationMenuTable()->getAll(array('navigation_menu_configuration_id' => $nNavigationMenuConfigurationId, 'navigation_level_id' => 1, 'sort' => $aSort)); } else { if (!$nNavigationMenuConfigurationId && $nNavigationModuleId) { $aMenu = $this->getNavigationMenuTable()->getAll(array('navigation_level_id' => 1, 'navigation_module_id' => $nNavigationModuleId, 'sort' => $aSort)); } else { $aMenu = $this->getNavigationMenuTable()->getAll(array('navigation_level_id' => 1, 'sort' => $aSort)); } } } if (count($aMenu)) { foreach ($aMenu as $oMenu) { $aNavigationMenu[$oMenu->id] = array('id' => $oMenu->id, 'navigation_level_id' => $oMenu->navigation_level_id, 'label_name' => $oMenu->label_name); $aSubmenu = $this->getNavigationMenuTable()->getAll(array('navigation_parent_menu_id' => $oMenu->id, 'sort' => $aSort)); if (count($aSubmenu)) { foreach ($aSubmenu as $oSubmenu) { $aNavigationMenu[$oMenu->id]['submenu'][$oSubmenu->id] = array('id' => $oSubmenu->id, 'navigation_level_id' => $oSubmenu->navigation_level_id, 'label_name' => $oSubmenu->label_name); $aSubsubmenu = $this->getNavigationMenuTable()->getAll(array('navigation_parent_menu_id' => $oSubmenu->id, 'sort' => $aSort)); if (count($aSubsubmenu)) { foreach ($aSubsubmenu as $oSubsubmenu) { $aNavigationMenu[$oMenu->id]['submenu'][$oSubmenu->id]['subsubmenu'][$oSubsubmenu->id] = array('id' => $oSubsubmenu->id, 'navigation_level_id' => $oSubsubmenu->navigation_level_id, 'label_name' => $oSubsubmenu->label_name); } } } } } } if ($this->getRequest()->isPost() && $this->params()->fromPost('form_name') === 'navigation_menu') { $oAddNewNavigationMenuForm->setData($this->getRequest()->getPost()); if ($oAddNewNavigationMenuForm->isValid()) { $oNavigationResourceEntity = new NavigationResourceEntity(); $oNavigationPrivilegeEntity = new NavigationPrivilegeEntity(); $oNavigationPrivilegeUserRoleEntity = new NavigationPrivilegeUserRoleEntity(); $oNavigationOptionEntity = new NavigationOptionEntity(); $oNavigationMenuEntity = new NavigationMenuEntity(); $oSiteSeoEntity = new SiteSeoEntity(); $oSiteSeoMetaKeywordsEntity = new SiteSeoMetaKeywordsEntity(); $oSiteSeoSiteSeoMetaKeywordsEntity = new SiteSeoSiteSeoMetaKeywordsEntity(); $oData = new \ArrayObject($oAddNewNavigationMenuForm->getData()); $oMakeHash = new MakeHash(); try { $this->getNavigationMenuTable()->beginTransaction(); if (!is_numeric($oData->offsetGet('navigation_module_id'))) { $oData->offsetSet('navigation_module_id', $this->getNavigationModuleTable()->findRow(array('value' => $oData->offsetGet('navigation_module_id')))); if (!is_numeric($oData->offsetGet('navigation_module_id'))) { throw new \Exception(); } } if (!is_numeric($oData->offsetGet('navigation_controller_id'))) { $oData->offsetSet('navigation_controller_id', $this->getNavigationControllerTable()->findRow(array('value' => $oData->offsetGet('navigation_controller_id')))); if (!is_numeric($oData->offsetGet('navigation_controller_id'))) { throw new \Exception(); } } if (!is_numeric($oData->offsetGet('navigation_action_id'))) { $oData->offsetSet('navigation_action_id', $this->getNavigationActionTable()->findRow(array('value' => $oData->offsetGet('navigation_action_id')))); if (!is_numeric($oData->offsetGet('navigation_action_id'))) { throw new \Exception(); } } $oData->offsetSet('navigation_module_name', $this->getNavigationModuleTable()->getRow(array('id' => $oData->offsetGet('navigation_module_id')))->value); $oData->offsetSet('navigation_controller_name', $this->getNavigationControllerTable()->getRow(array('id' => $oData->offsetGet('navigation_controller_id')))->value); $oData->offsetSet('navigation_action_name', $this->getNavigationActionTable()->getRow(array('id' => $oData->offsetGet('navigation_action_id')))->value); $oNavigationResourceValue = new \ArrayObject(array('value' => $oData->offsetGet('navigation_module_name'))); $oNavigationPrivilegeValue = new \ArrayObject(array('value' => $oData->offsetGet('navigation_controller_name') . ':' . $oData->offsetGet('navigation_action_name'), 'unique_key' => md5($oData->offsetGet('navigation_module_name') . $oData->offsetGet('navigation_controller_name') . $oData->offsetGet('navigation_action_name') . $this->getSiteHref($oData->offsetGet('label_name')) . 'html'))); $oData->offsetSet('navigation_resource_id', $this->getNavigationResourceTable()->addRow($oNavigationResourceEntity->setOptions($oNavigationResourceValue))); $oData->offsetSet('navigation_privilege_id', $this->getNavigationPrivilegeTable()->addRow($oNavigationPrivilegeEntity->setOptions($oNavigationPrivilegeValue))); if ($oData->offsetGet('navigation_privilege_id') && is_array($oData->offsetGet('user_role_id')) && count($oData->offsetGet('user_role_id'))) { foreach ($oData->offsetGet('user_role_id') as $nValue) { $oNavigationPrivilegeUserRoleValue = new \ArrayObject(array('navigation_privilege_id' => $oData->offsetGet('navigation_privilege_id'), 'user_role_id' => $nValue)); $this->getNavigationPrivilegeUserRoleTable()->addRow($oNavigationPrivilegeUserRoleEntity->setOptions($oNavigationPrivilegeUserRoleValue)); } } if ($oData->offsetGet('navigation_resource_id') && $oData->offsetGet('navigation_privilege_id')) { $oNavigationOptionValue = new \ArrayObject(array('navigation_module_id' => $oData->offsetGet('navigation_module_id'), 'navigation_controller_id' => $oData->offsetGet('navigation_controller_id'), 'navigation_action_id' => $oData->offsetGet('navigation_action_id'), 'navigation_privilege_id' => $oData->offsetGet('navigation_privilege_id'), 'navigation_resource_id' => $oData->offsetGet('navigation_resource_id'))); $oData->offsetSet('navigation_option_id', $this->getNavigationOptionTable()->addRow($oNavigationOptionEntity->setOptions($oNavigationOptionValue))); if ($oData->offsetGet('navigation_option_id')) { $oSiteSeoValue = new \ArrayObject(array('site_seo_robots_id' => $oData->offsetGet('site_seo_robots_id'), 'head_title' => $oData->offsetGet('head_title'), 'meta_description' => $oData->offsetGet('meta_description'))); $oData->offsetSet('site_seo_id', $this->getSiteSeoTable()->addRow($oSiteSeoEntity->setOptions($oSiteSeoValue))); if ($oData->offsetGet('site_seo_id') && is_array($oData->offsetGet('site_seo_meta_keywords_id')) && count($oData->offsetGet('site_seo_meta_keywords_id'))) { foreach ($oData->offsetGet('site_seo_meta_keywords_id') as $nValue) { $oSiteSeoSiteSeoMetaKeywordsValue = new \ArrayObject(array('site_seo_id' => $oData->offsetGet('site_seo_id'), 'site_seo_meta_keywords_id' => $nValue)); $this->getSiteSeoSiteSeoMetaKeywordsTable()->addRow($oSiteSeoSiteSeoMetaKeywordsEntity->setOptions($oSiteSeoSiteSeoMetaKeywordsValue)); } } $oNavigationMenuValue = new \ArrayObject(array('navigation_menu_configuration_id' => $oData->offsetGet('navigation_menu_configuration_id'), 'navigation_menu_type_id' => $oData->offsetGet('navigation_menu_type_id'), 'navigation_option_id' => $oData->offsetGet('navigation_option_id'), 'navigation_level_id' => $oData->offsetGet('navigation_level_id'), 'navigation_parent_menu_id' => $oData->offsetGet('navigation_parent_menu_id'), 'navigation_parent_submenu_id' => $oData->offsetGet('navigation_parent_submenu_id'), 'navigation_layout_id' => $oData->offsetGet('navigation_layout_id'), 'site_seo_id' => $oData->offsetGet('site_seo_id'), 'label_name' => $oData->offsetGet('label_name'), 'description' => $oData->offsetGet('description'), 'image_id' => $oData->offsetExists('image_id') ? $oData->offsetGet('image_id') : null, 'visible' => $oData->offsetGet('visible'))); $oData->offsetSet('navigation_menu_id', $this->getNavigationMenuTable()->addRow($oNavigationMenuEntity->setOptions($oNavigationMenuValue))); } if ($oData->offsetGet('navigation_menu_id')) { $this->getNavigationMenuTable()->commit(); $this->redirect()->toRoute('application_navigation/application_navigation_process', array('action' => 'menu'), array()); } } } catch (\Exception $e) { $this->getNavigationMenuTable()->rollBack(); } } } return new ViewModel(array('navigation_menu' => $aNavigationMenu, 'add_new_navigation_menu_form' => $oAddNewNavigationMenuForm, 'edit_navigation_menu_form' => $oEditNavigationMenuForm, 'menu_item_settings' => $oMenuItemSettingsForm, 'change_menu_configuration_form' => $oChangeMenuConfigurationForm, 'add_new_navigation_menu_configuration_form' => $oAddNewNavigationMenuConfigurationForm, 'edit_navigation_menu_configuration_form' => $oEditNavigationMenuConfigurationForm, 'add_new_site_seo_meta_keyword_form' => $oAddNewSiteSeoMetaKeywordsForm, 'edit_site_seo_meta_keyword_form' => $oEditSiteSeoMetaKeywordsForm)); }