/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Assignment::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', 'user', $this->user])->andFilterWhere(['like', 'role', $this->role]);
     return $dataProvider;
 }
 public function actionRole($user)
 {
     $userRoles = Assignment::find()->select('role')->where(['user' => $user])->indexBy('role')->all();
     if (\Yii::$app->request->isPost) {
         $selectedRoles = LuLu::getPostValue('roles', []);
         Assignment::deleteAll(['and', 'user=\'' . $user . '\'', ['not in', 'role', $selectedRoles]]);
         foreach ($selectedRoles as $selectedRole) {
             if ($userRoles != null && isset($userRoles[$selectedRole])) {
                 continue;
             }
             $newAssignment = new Assignment();
             $newAssignment->user = $user;
             $newAssignment->role = $selectedRole;
             $newAssignment->save();
         }
         return $this->redirect(['role', 'user' => $user]);
     }
     $allRoles = Role::findAll();
     return $this->render('role', ['userRoles' => $userRoles, 'allRoles' => $allRoles]);
 }