Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthRole::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'operation_list', $this->operation_list]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Checks if the user can perform the operation as specified by the given permission.
  *
  * if super admin, the operation role is 'all', return true all the time.
  *
  *
  * @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
  * @param array $params name-value pairs that would be passed to the rules associated
  * with the roles and permissions assigned to the user. A param with name 'user' is added to
  * this array, which holds the value of [[id]].
  * @param boolean $allowCaching whether to allow caching the result of access check.
  * When this parameter is true (default), if the access check of an operation was performed
  * before, its result will be directly returned when calling this method to check the same
  * operation. If this parameter is false, this method will always call
  * [[\yii\rbac\ManagerInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
  * caching is effective only within the same request and only works when `$params = []`.
  * @return boolean whether the user can perform the operation as specified by the given permission.
  */
 public function can($permissionName, $params = [], $allowCaching = true)
 {
     if ($allowCaching && isset($this->_operations)) {
         $operations = $this->_operations;
     } else {
         $operations = AuthRole::findOne(Yii::$app->user->identity->auth_role)->operation_list;
         $this->_operations = $operations;
         //super admin
         if ($operations == 'all') {
             return true;
         }
     }
     if (strpos(';' . $operations . ';', $permissionName) === false) {
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 3
0
 public static function getArrayAuthRole()
 {
     return ArrayHelper::map(AuthRole::find()->all(), 'id', 'name');
 }
Exemplo n.º 4
0
 /**
  * Finds the AuthRole model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AuthRole the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AuthRole::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }