public function actionDel()
 {
     $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : '';
     if ($id != '') {
         $ret = Action::model()->deleteByPk($id);
         RoleAction::model()->deleteAll('aid=:aid', array(':aid' => $id));
         var_dump($ret);
     } else {
         echo "fail";
     }
 }
示例#2
0
 /**
  * findRole 
  *
  * 获取带有action的role信息
  * 
  * @param mixed $rid roleid
  * @return void
  */
 public function findRole($rid)
 {
     $roleInfo = $this->find('rid=:id', array(':id' => $rid));
     if (!empty($roleInfo)) {
         $roleInfo = $roleInfo->getAttributes();
     } else {
         return array();
     }
     // get 该角色的action列表
     $roleInfo['actions'] = RoleAction::model()->findActions($rid);
     //echo "<pre>";var_dump($roleInfo['actions']);exit;
     return $roleInfo;
 }
示例#3
0
 public static function getAllowedAction($controllerId, $role_id)
 {
     //TODO: Using cache to speed process
     $output = [];
     foreach (Action::find()->where(["controller_id" => $controllerId])->all() as $action) {
         //bypass for super admin
         if ($role_id == 1) {
             $output[] = $action->action_id;
         } else {
             $roleAction = RoleAction::find()->where(["action_id" => $action->id, "role_id" => $role_id])->one();
             if ($roleAction) {
                 $output[] = $action->action_id;
             }
         }
     }
     return $output;
 }
示例#4
0
文件: Role.php 项目: Jazzee/Jazzee
 /**
  * Add actions
  *
  * @param Entity\RoleAction $action
  */
 public function addAction(RoleAction $action)
 {
     $this->actions[] = $action;
     if ($action->getRole() != $this) {
         $action->setRole($this);
     }
 }
 public function actionEdit()
 {
     //echo "<pre>";var_dump($_REQUEST);exit;
     $role = new Role();
     $roleInfo = array();
     $label = '';
     foreach ($_REQUEST as $k => $v) {
         if ($k != 'actions' && $k != 'positions') {
             $_REQUEST[$k] = trim($v);
         }
     }
     // action 列表 展现
     $action = new Action();
     $actionList = $action->findAll('1=1 order by is_menu desc, route desc');
     $retActions = array();
     foreach ($actionList as $v) {
         $parts = explode("/", $v['route']);
         //if(!isset($parts[1])) continue;
         if (!isset($parts[1])) {
             $retActions["noroute"][] = $v->getAttributes();
         }
         $retActions[$parts[1]][] = $v->getAttributes();
     }
     //echo "<pre>";var_dump($retActions);exit;
     if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
         // 修改
         $roleInfo = $role->findRole($_REQUEST['id']);
         //echo "<pre>";var_dump($retActions,$roleInfo['actions']);exit;
         if (!empty($_REQUEST['modify'])) {
             $role->updateRole($_REQUEST);
             $this->redirect('/main/role/list');
         }
     } elseif (!empty($_REQUEST['name'])) {
         // 新增
         $roleInfo = $role->find('rname=:name', array(':name' => $_REQUEST['name']));
         if (!empty($roleInfo)) {
             $roleInfo = $roleInfo->getAttributes();
             $roleInfo['actions'] = RoleAction::model()->findActions($roleInfo['rid']);
             $this->render('edit', array('action_list' => $retActions, 'entity' => $roleInfo, 'label' => 'has_role'));
             exit;
         }
         if (!empty($_REQUEST['modify'])) {
             $role->saveRole($_REQUEST);
             $this->redirect('/main/role/list');
         }
     }
     // foreach($actionList as $k=>$v) {
     // echo "<pre>";var_dump($k,$v->getAttributes());
     // }exit;
     $this->render('edit', array('action_list' => $retActions, 'entity' => $roleInfo, 'label' => $label));
 }