コード例 #1
0
 /**
  * @param \System\Model\Action $item
  * @return true|false
  */
 public function save($item)
 {
     $data = array('controllerId' => $item->getControllerId(), 'name' => $item->getName(), 'description' => $item->getDescription() ?: null, 'status' => $item->getStatus(), 'display' => $item->getDisplay(), 'createdById' => $item->getCreatedById(), 'createdDateTime' => $item->getCreatedDateTime(), 'updatedDateTime' => $item->getUpdatedDateTime() ?: null);
     $results = false;
     $dbAdapter = $this->getDbAdapter();
     if (null === ($id = $item->getId())) {
         $insert = $this->getDbSql()->insert(self::TABLE_NAME);
         $insert->values($data);
         $query = $this->getDbSql()->buildSqlString($insert);
         $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
         $item->setId($dbAdapter->getDriver()->getLastGeneratedValue());
     } else {
         $update = $this->getDbSql()->update(self::TABLE_NAME);
         $update->set($data);
         $update->where(array("id" => (int) $item->getId()));
         $selectString = $this->getDbSql()->buildSqlString($update);
         $results = $dbAdapter->query($selectString, $dbAdapter::QUERY_MODE_EXECUTE);
     }
     return $results;
 }
コード例 #2
0
 public function updatemcaAction()
 {
     $request = $this->getRequest();
     $sl = $this->getServiceLocator();
     $mcaRole = $this->getRequest()->getPost('mca_role');
     $id = $this->getRequest()->getPost('id');
     $name = $this->getRequest()->getPost('name');
     $description = $this->getRequest()->getPost('description');
     $jsonModel = new JsonModel();
     if (!$id || !$mcaRole || !$name) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]);
         return $jsonModel;
     }
     switch ($mcaRole) {
         case 'action':
             $action = new \System\Model\Action();
             $action->setId($id);
             $actionMapper = $sl->get('System\\Model\\ActionMapper');
             if (!$actionMapper->get($action)) {
                 $jsonModel->setVariables(['code' => 0, 'messages' => ['Không tìm thấy Action']]);
                 return $jsonModel;
             }
             if ($name) {
                 $action->setName($name);
             }
             if ($description) {
                 $action->setDescription($description);
             } else {
                 $action->setDescription(null);
             }
             if (!$actionMapper->isExisted($action)) {
                 $actionMapper->save($action);
                 $jsonModel->setVariables(['code' => 1]);
             } else {
                 $jsonModel->setVariables(['code' => 0, 'messages' => ['Tên action đã tồn tại']]);
             }
             return $jsonModel;
         case 'controller':
             $controller = new \System\Model\Controller();
             $controller->setId($id);
             $controllerMapper = $sl->get('System\\Model\\ControllerMapper');
             if (!$controllerMapper->get($controller)) {
                 $jsonModel->setVariables(['code' => 0, 'messages' => ['Không tìm thấy Controller']]);
                 return $jsonModel;
             }
             if ($name) {
                 $controller->setName($name);
             }
             if ($description) {
                 $controller->setDescription($description);
             } else {
                 $controller->setDescription(null);
             }
             if (!$controllerMapper->isExisted($controller)) {
                 $controllerMapper->save($controller);
                 $jsonModel->setVariables(['code' => 1]);
             } else {
                 $jsonModel->setVariables(['code' => 0, 'messages' => ['Tên controller đã tồn tại']]);
             }
             return $jsonModel;
         case 'module':
             $module = new \System\Model\Module();
             $module->setId($id);
             $moduleMapper = $sl->get('System\\Model\\ModuleMapper');
             if (!$moduleMapper->get($module)) {
                 $jsonModel->setVariables(['code' => 0, 'messages' => ['Không tìm thấy Controller']]);
                 return $jsonModel;
             }
             if ($name) {
                 $module->setName($name);
             }
             if ($description) {
                 $module->setDescription($description);
             } else {
                 $module->setDescription(null);
             }
             if (!$moduleMapper->isExisted($module)) {
                 $moduleMapper->save($module);
                 $jsonModel->setVariables(['code' => 1]);
             } else {
                 $jsonModel->setVariables(['code' => 0, 'messages' => ['Tên module đã tồn tại']]);
             }
             return $jsonModel;
         default:
             $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]);
             return $jsonModel;
     }
 }
コード例 #3
0
 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;
 }