예제 #1
0
파일: Role.php 프로젝트: bjtenao/tudu-web
 /**
  * 创建权限组
  *
  * @param array $params
  */
 public function create(array $params)
 {
     // 组织ID必须有
     if (empty($params['orgid'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing or invalid value of parameter "orgid"', self::CODE_INVALID_ORGID);
     }
     // 权限组名称,必须有
     if (empty($params['rolename'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing or invalid value of parameter "groupname"', self::CODE_INVALID_ROLENAME);
     }
     /* @var $daoRole Dao_Md_User_Role */
     $daoRole = Tudu_Dao_Manager::getDao('Dao_Md_User_Role', Tudu_Dao_Manager::DB_MD);
     $orgId = $params['orgid'];
     $roleName = $params['rolename'];
     $roleId = !empty($params['roleid']) ? $params['roleid'] : Dao_Md_User_Role::getRoleId($orgId, $roleName);
     // 创建权限组
     $ret = $daoRole->createRole(array('orgid' => $orgId, 'roleid' => $roleId, 'rolename' => $roleName));
     if (!$ret) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Create role failed', self::CODE_SAVE_FAILED);
     }
     return true;
 }
예제 #2
0
 /**
  * 创建权限组
  */
 public function createAction()
 {
     $roleName = trim($this->_request->getPost('rolename'));
     if (!$roleName) {
         return $this->json(false, $this->lang['invalid_params_rolename']);
     }
     /* @var $modelRole Model_User_Role*/
     $modelRole = Tudu_Model::factory('Model_User_Role');
     try {
         $roleId = Dao_Md_User_Role::getRoleId($this->_orgId, $roleName);
         $modelRole->execute('create', array(array('orgid' => $this->_orgId, 'roleid' => $roleId, 'rolename' => $roleName)));
     } catch (Model_User_Exception $e) {
         switch ($e->getCode()) {
             case Model_User_Role::CODE_INVALID_ORGID:
                 $message = '缺少参数[orgid]';
                 break;
             case Model_User_Role::CODE_INVALID_ROLENAME:
                 $message = $this->lang['invalid_params_rolename'];
                 break;
             case Model_User_Role::CODE_SAVE_FAILED:
                 $message = $this->lang['role_create_failure'];
                 break;
         }
         return $this->json(false, $message);
     }
     $this->_createLog('role', 'create', null, $roleId, array('rolename' => $roleName));
     $this->json(true, $this->lang['role_create_success'], array('roleid' => $roleId, 'rolename' => $roleName));
 }