Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AnswerList::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $sort = $dataProvider->getSort();
     $sort->attributes['officeName'] = ['asc' => ['office.name' => SORT_ASC], 'desc' => ['office.name' => SORT_DESC], 'label' => 'Отделение'];
     $sort->attributes['statusName'] = ['asc' => ['status' => SORT_ASC], 'desc' => ['status' => SORT_DESC], 'label' => 'Статус'];
     $dataProvider->setSort($sort);
     $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');
         $query->joinWith(['office']);
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'question_list_id' => $this->question_list_id]);
     $query->andFilterWhere(['like', 'status', $this->statusName])->andFilterWhere(['like', 'list_name', $this->list_name])->andFilterWhere(['>=', 'date_from', $this->date_from])->andFilterWhere(['<=', 'date_to', $this->date_to]);
     $query->joinWith(['office' => function ($q) {
         $q->andFilterWhere(['like', 'office.name', $this->officeName]);
     }]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // берем ID отделений, где пользователь является управляющим, или где он назначен им.
     $officeIds = $this->getOffiсeIds(Yii::$app->user->identity->username);
     $query = AnswerList::find()->innerJoinWith('questionList')->where(['do_id' => $officeIds]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $sort = $dataProvider->getSort();
     $sort->attributes['officeName'] = ['asc' => ['office.name' => SORT_ASC], 'desc' => ['office.name' => SORT_DESC], 'label' => 'Отделение'];
     $sort->attributes['statusName'] = ['asc' => ['status' => SORT_ASC], 'desc' => ['status' => SORT_DESC], 'label' => 'Статус'];
     $dataProvider->setSort($sort);
     $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');
         $query->joinWith(['office']);
         return $dataProvider;
     }
     $query->andFilterWhere(['answer_list.id' => $this->id, 'question_list_id' => $this->question_list_id]);
     $query->andFilterWhere(['like', 'status', $this->statusName])->andFilterWhere(['like', 'list_name', $this->list_name])->andFilterWhere(['>=', 'date_from', $this->date_from])->andFilterWhere(['<=', 'date_to', $this->date_to]);
     $query->joinWith(['office' => function ($q) {
         $q->andFilterWhere(['like', 'office.name', $this->officeName]);
     }]);
     return $dataProvider;
 }