コード例 #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' => ['questionlist_office.name' => SORT_ASC], 'desc' => ['questionlist_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(['questionlist_office']);
         return $dataProvider;
     }
     $query->joinWith('questionList');
     $query->andFilterWhere(['id' => $this->id, 'question_list_id' => $this->question_list_id, 'scores' => $this->scores, 'date' => $this->date]);
     $query->andFilterWhere(['>=', 'date_from', $this->date_from])->andFilterWhere(['<=', 'date_to', $this->date_to]);
     if (!$this->statusName) {
         $query->andFilterWhere(['not like', 'status', 'archive']);
     } else {
         $query->andFilterWhere(['like', 'status', $this->statusName]);
     }
     $query->joinWith(['office' => function ($q) {
         $q->andFilterWhere(['like', 'questionlist_office.name', $this->officeName]);
     }]);
     return $dataProvider;
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AnswerList::find()->with('questionList')->orderBy('status');
     $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(['id' => $this->id, 'question_list_id' => $this->question_list_id, 'date_from' => $this->date_from, 'date_to' => $this->date_to, 'date' => $this->date, 'do_id' => $this->officeName, 'scores' => $this->scores]);
     if ($this->statusName) {
         $query->andFilterWhere(['like', 'status', $this->statusName]);
     } else {
         $query->andFilterWhere(['not like', 'status', 'archive']);
     }
     return $dataProvider;
 }
コード例 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // Если админ, то выбираем все опросы.
     if ($isAdmin = Users::findOne(['profile_id' => Yii::$app->user->identity->username, 'profile_office_role' => 'admin'])) {
         $officeIds = ArrayHelper::map(Office::find()->all(), 'id', 'id');
     } elseif ($isCommercialDirector = Users::findAll(['profile_id' => Yii::$app->user->identity->username, 'profile_office_role' => 'commercial_director'])) {
         // берем ID отделений, где регион отделения === региону, где пользователь коммерч.директор
         $regionIds = ArrayHelper::map($isCommercialDirector, 'region_id', 'region_id');
         $officeIds = ArrayHelper::map(Office::findAll(['region_id' => $regionIds]), 'id', 'id');
     } else {
         // берем ID отделений, где пользователь является управляющим, или где он назначен им.
         $officeIds = $this->getOffiсeIds(Yii::$app->user->identity->username);
     }
     $query = AnswerList::find()->joinWith('questionList')->where(['do_id' => $officeIds]);
     //$query = AnswerList::find()->innerJoinWith('questionList');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $sort = $dataProvider->getSort();
     $sort->attributes['officeName'] = ['asc' => ['questionlist_office.name' => SORT_ASC], 'desc' => ['questionlist_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(['questionlist_office']);
         return $dataProvider;
     }
     $query->andFilterWhere(['questionlist_answer_list.id' => $this->id, 'question_list_id' => $this->question_list_id, 'scores' => $this->scores]);
     $query->andFilterWhere(['>=', 'date_from', $this->date_from])->andFilterWhere(['<=', 'date_to', $this->date_to]);
     if ($this->statusName) {
         $query->andFilterWhere(['like', 'status', $this->statusName]);
     } else {
         $query->andFilterWhere(['not like', 'status', 'archive']);
     }
     $query->joinWith(['office' => function ($q) {
         $q->andFilterWhere(['like', 'questionlist_office.name', $this->officeName]);
     }]);
     return $dataProvider;
 }
コード例 #4
0
 /**
  * Finds the AnswerList model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AnswerList the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelWithRelations($id)
 {
     $query = AnswerList::find(['id' => $id])->with(['answers' => function ($q) {
         $q->with(['question' => function ($q) {
             $q->with('answerVariants');
         }]);
     }]);
     $model = $query->one();
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #5
0
 protected function findModelAnswerList($id)
 {
     $model = AnswerList::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     if ($model->status == 'clear') {
         return $model;
     }
     $query = AnswerList::find(['id' => $id])->with(['questionList' => function ($query) {
         $query->with('questions');
     }])->joinWith(['answers' => function ($q) {
         $q->with(['question' => function ($q) {
             $q->with('answerVariants');
         }]);
     }])->where(['questionlist_answer_list.id' => $id, 'questionlist_answers.answer_list_id' => $id]);
     $model = $query->one();
     if ($model) {
         return $model;
     } else {
         throw new NotFoundHttpException('Не найдено.');
     }
 }