/** * Lists all Relation models. * @return mixed */ public function actionIndex($role) { if (\Yii::$app->request->isPost) { $selectedPermissions = LuLu::getPostValue('Permission'); Relation::AddBatchItems($role, $selectedPermissions); return $this->redirect(['index', 'role' => $role]); } $allPermissions = Permission::getAllPermissionsGroupedByCategory(); $rolePermissions = Relation::find()->select(['permission', 'value'])->where(['role' => $role])->indexBy('permission')->all(); $categories = Permission::getCategoryItems(); $role = Role::findOne(['id' => $role]); return $this->render('index', ['rolePermissions' => $rolePermissions, 'allPermissions' => $allPermissions, 'categories' => $categories, 'role' => $role]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Relation::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', 'role', $this->role])->andFilterWhere(['like', 'permission', $this->permission])->andFilterWhere(['like', 'value', $this->value]); return $dataProvider; }