Exemplo n.º 1
0
 /**
  * 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 any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'role', $this->role])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 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]);
 }