public function deleteAction() { $jsonModel = new JsonModel(); $id = trim($this->getRequest()->getPost('id')); if (!$id) { $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]); return $jsonModel; } $role = new \System\Model\Role(); $role->setId($id); $roleMapper = $this->getServiceLocator()->get('\\System\\Model\\RoleMapper'); if (!$roleMapper->get($role)) { $jsonModel->setVariables(['code' => 0, 'messages' => ['Không tìm thấy role']]); return $jsonModel; } if ($roleMapper->isRoleUsed($role)) { $jsonModel->setVariables(['code' => 0, 'messages' => ['Quyền đang được sử dụng, không thể xóa']]); return $jsonModel; } $roleMapper->delete($role); $jsonModel->setVariable('code', 1); return $jsonModel; }
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\Role $item */ public function fetchAll($item) { $dbAdapter = $this->getDbAdapter(); $select = $this->getDbSql()->select(self::TABLE_NAME); if ($item->getOption('names')) { $select->where(['name' => $item->getOption('names')]); } $query = $this->getDbSql()->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); $result = []; if ($rows->count()) { foreach ($rows as $row) { $role = new \System\Model\Role(); $role->exchangeArray((array) $row); $result[] = $role; } } return $result; }