/** * 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; }
/** * 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; }
/** * 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; }
<?php use yii\widgets\DetailView; use yii\grid\GridView; use app\modules\unicred\questionlist\models\AnswerList; /* @var $this yii\web\View */ /* @var $model app\modules\unicred\questionlist\models\AnswerList */ $statusList = AnswerList::getStatusList(); ?> <div class="answer-list-delete"> <p> Данный опрос находится в статусе <b>"<?php echo $model->statusName; ?> "</b>.<br/> Перенести в архив невозможно. <?php if ($model->status == 'archive') { ?> Опрос уже находится в данной группе. <?php } ?> </p> <p> Для переноса в архив, опрос должен быть в статусе <br> <b>"<?php echo $statusList['done']; ?> "</b>. </p> </div>
/** * Проверка, можно ли изменять содержание опроса, после того, * как он назначен отделениям. */ public function canCreateQuestion($question_list_id) { // Назначен ли опрос отделениям $modelsAnswerList = AnswerList::findAll(['question_list_id' => $question_list_id]); return !$modelsAnswerList; }
/** * 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.'); } }
public function getAnswerLists() { return $this->hasMany(AnswerList::className(), ['question_list_id' => 'id']); }
<div class="answer-list-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, "question_list_id")->dropDownList($questionLists, [$model->question_list_id => ['selected' => 'selected']]); ?> <?php if (!$model->isNewRecord) { ?> <?php echo $form->field($model, "status")->dropDownList(AnswerList::getStatusList(), [$model->status => ['selected' => 'selected']]); ?> <?php } ?> <?php echo $form->field($model, "do_id")->dropDownList($DoList, [$model->question_list_id => ['selected' => 'selected']]); ?> <div class="form-group field-answerlist-dates"> <?php echo DatePicker::widget(['name' => 'date_from', 'type' => DatePicker::TYPE_RANGE, 'name2' => 'date_to', 'form' => $form, 'model' => $model, 'attribute' => 'date_from', 'attribute2' => 'date_to', 'language' => 'ru', 'separator' => ' - ', 'pluginOptions' => ['format' => 'yyyy-mm-dd']]); ?> </div> <?php
<?php use yii\helpers\Url; use yii\helpers\ArrayHelper; use app\modules\unicred\questionlist\models\Office; use app\modules\unicred\questionlist\models\AnswerList; use yii\helpers\Html; return [['class' => 'kartik\\grid\\SerialColumn', 'width' => '30px'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'questionList.title'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'date_from'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'date_to'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'statusName', 'filter' => AnswerList::getStatusList()], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'officeName', 'filter' => ArrayHelper::map(Office::find()->all(), 'id', 'name')], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'date'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'author'], ['class' => '\\kartik\\grid\\ActionColumn', 'template' => '{confirm}', 'buttons' => ['confirm' => function ($url, $model) { return Html::a('<span class="glyphicon glyphicon-list"></span>', Url::toRoute(['confirm', 'id' => $model->id])); }]]];
protected function findAnswerListModel($answer_list_id) { $model = AnswerList::findOne($answer_list_id); return $model; }
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('Не найдено.'); } }