/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Permission::find()->where(['type' => Permission::TYPE]); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Finds the Permission model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $name * @return Permission the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($name) { $model = new Permission(); $permission = $model->authManager->getPermission($name); if (!($permission === null)) { $model->name = $permission->name; $model->description = $permission->description; $model->setIsNewRecord(false); return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return array */ public static function getRbacItems() { /** * @var $role Role * @var $permission Permission */ $roles = []; $permissions = []; foreach (Role::find()->where(['type' => Role::TYPE])->all() as $role) { $roles = ArrayHelper::merge($roles, [$role->name => $role->name]); } foreach (Permission::find()->where(['type' => Permission::TYPE])->all() as $permission) { $permissions = ArrayHelper::merge($permissions, [$permission->name => $permission->name]); } return ['roles' => $roles, 'permissions' => $permissions]; }
/** * @return array */ public function getPermissions() { /* @var $model Permission */ $permissions = []; $models = Permission::find()->where(['type' => Permission::TYPE])->all(); foreach ($models as $model) { $permissions = ArrayHelper::merge($permissions, [$model->name => $model->name]); } return $permissions; }