public function updaterolefeatureAction() { $actionId = $this->getRequest()->getPost('actionId'); $roleId = $this->getRequest()->getPost('roleId'); $value = $this->getRequest()->getPost('value'); $jsonModel = new JsonModel(); if (in_array($roleId, array(\User\Model\User::ROLE_ADMIN, \User\Model\User::ROLE_SUPERADMIN, \User\Model\User::ROLE_MEMBER, \User\Model\User::ROLE_GUEST))) { $jsonModel->setVariables(array('code' => 0, 'messages' => ['Không thể điều chỉnh quyền này của nhóm người dùng này'])); return $jsonModel; } $role = new \System\Model\Role(); $role->setId($roleId); $roleMapper = $this->getServiceLocator()->get('\\System\\Model\\RoleMapper'); if (!$roleMapper->get($role)) { $jsonModel->setVariables(array('code' => 0, 'messages' => ['Không tìm thấy quyền này'])); return $jsonModel; } $action = new Action(); $action->setId($actionId); $actionMapper = $this->getServiceLocator()->get('\\System\\Model\\ActionMapper'); if (!$actionMapper->get($action)) { $jsonModel->setVariables(array('code' => 0, 'messages' => ['Không tìm thấy action này'])); return $jsonModel; } $roleFeature = new \System\Model\Role\Feature(); $roleFeature->setActionId($actionId); $roleFeature->setRoleId($roleId); $roleFeatureMapper = $this->getServiceLocator()->get('\\System\\Model\\Role\\FeatureMapper'); if ($value) { if (!$roleFeatureMapper->isExisted($roleFeature)) { $roleFeature->setCreatedById($this->user()->getIdentity()); $roleFeature->setCreatedDateTime(DateBase::getCurrentDateTime()); $roleFeatureMapper->save($roleFeature); } } else { if ($roleFeatureMapper->isExisted($roleFeature)) { $roleFeatureMapper->delete($roleFeature); } } $jsonModel->setVariable('code', 1); return $jsonModel; }
/** * @author KienNN * @param \System\Model\Action $item */ public function getByPath($item) { if (!$item->getOption('path') && (!$item->getOption('moduleName') || !$item->getOption('controllerName') || !$item->getName())) { return null; } $names = []; if ($item->getOption('path')) { $path = explode('/', $item->getOption('path')); if (count($path) != 4) { return null; } $name['module'] = $path[1]; $name['controller'] = $path[2]; $name['action'] = $path[3]; } else { $name['module'] = $item->getOption('moduleName'); $name['controller'] = $item->getOption('controllerName'); $name['action'] = $item->getName(); } $dbAdapter = $this->getDbAdapter(); $select = $this->getDbSql()->select(['sa' => self::TABLE_NAME]); $select->join(['sc' => \System\Model\ControllerMapper::TABLE_NAME], 'sa.controllerId = sc.id', []); $select->join(['sm' => \System\Model\ModuleMapper::TABLE_NAME], 'sc.moduleId=sm.id', []); $select->where(['sa.name' => $name['action'], 'sc.name' => $name['controller'], 'sm.name' => $name['module']]); $select->limit(1); $query = $this->getDbSql()->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { $item->exchangeArray((array) $rows->current()); return $item; } return null; }
public function adddependencyAction() { $actionId = $this->getRequest()->getPost('id'); $dependencies = $this->getRequest()->getPost('dependencies'); $jsonModel = new JsonModel(); if (!$actionId) { $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]); return $jsonModel; } $dependencyMapper = $this->getServiceLocator()->get('System\\Model\\Action\\DependencyMapper'); $dependencyMapper->delete($actionId); if ($dependencies && is_array($dependencies) && count($dependencies)) { $moduleMapper = $this->getServiceLocator()->get('System\\Model\\ModuleMapper'); $controllerMapper = $this->getServiceLocator()->get('System\\Model\\ControllerMapper'); $actionMapper = $this->getServiceLocator()->get('System\\Model\\ActionMapper'); foreach ($dependencies as $actionLink) { $names = explode('/', $actionLink); if (count($names) != 4) { continue; } $moduleName = $names[1]; $controllerName = $names[2]; $actionName = $names[3]; $module = new \System\Model\Module(); $module->setName($moduleName); if (!$moduleMapper->get($module)) { continue; } $controller = new \System\Model\Controller(); $controller->setName($controllerName); $controller->setModuleId($module->getId()); if (!$controllerMapper->get($controller)) { continue; } $action = new \System\Model\Action(); $action->setControllerId($controller->getId()); $action->setName($actionName); if (!$actionMapper->get($action)) { continue; } $dependency = new \System\Model\Action\Dependency(); $dependency->setActionId($actionId); $dependency->setDependencyId($action->getId()); if (!$dependencyMapper->isExisted($dependency)) { $dependencyMapper->save($dependency); } } } $jsonModel->setVariables(['code' => 1]); return $jsonModel; }