/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Task::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['name' => SORT_ASC]]]); $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([self::tableName() . '.category' => $this->category, self::tableName() . '.active' => $this->active]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['>=', 'min_hours', $this->min_hours])->andFilterWhere(['<=', 'max_hours', $this->max_hours]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $way = null) { if ($way == null) { $query = Task::find(); } else { $query = $way; } $dataProvider = new ActiveDataProvider(['query' => $query]); $query->joinWith('taskType'); $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, 'teacher_id' => $this->teacher_id]); $query->andFilterWhere(['like', 'task.name', $this->name])->andFilterWhere(['like', 'task.text', $this->text])->andFilterWhere(['like', 'task_type.name', $this->type_id]); return $dataProvider; }
/*= $form->field($model, 'invoice_id')->dropDownList(\yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName'), ['prompt' => '', 'id' => 'location-select']) */ ?> <?php echo $form->field($model, 'invoice_id')->widget(\kartik\select2\Select2::className(), ['data' => \yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName'), 'options' => ['prompt' => '', 'id' => 'location-select']]); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->textArea(['rows' => 5]); ?> <?php echo $form->field($model, 'task_id')->widget(\kartik\select2\Select2::className(), ['data' => \yii\helpers\ArrayHelper::map(\common\models\Task::find()->active()->all(), 'id', 'name'), 'options' => ['prompt' => '', 'id' => 'task-select'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php //TODO: Allow this list to dynamically populate using keywords through ajax... ?> <?php echo $form->field($model, 'priority_id')->dropDownList($model::$PRIORITIES, ['prompt' => '']); ?> <?php echo $form->field($model, 'bill_type_id')->widget(\kartik\depdrop\DepDrop::className(), ['data' => $model::$BILL_TYPE_SELECT, 'options' => ['prompt' => '', 'options' => [$model::BILL_PROACTIVE => ['disabled' => !($model->invoice && $model->invoice->location->proactive)]]], 'pluginOptions' => ['depends' => ['location-select'], 'url' => Url::to(['ajax-bill-type']), 'placeholder' => '']]); ?> </p> <?php
echo Select2::widget(['name' => 'task_type', 'id' => 'task_type', 'value' => $model->task->taskType->id, 'data' => ArrayHelper::map(TaskType::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Выберите тип заданий ...', 'onchange' => ' $.post( "' . Url::to(['//task/listbytype', 'id' => '']) . '"+$(this).val(), function( data ) { $( "select#task" ).html( data ); }); '], 'pluginOptions' => ['tags' => true]]); ?> <?php echo Html::tag('br'); ?> <?php echo Html::label('Задание'); ?> <?php echo Select2::widget(['name' => 'task', 'id' => 'task', 'value' => $model->task->id, 'data' => ArrayHelper::map(Task::find()->where(['type_id' => $model->task->taskType->id])->all(), 'id', 'name'), 'options' => ['placeholder' => 'Выберите задание ...', 'onchange' => ' $.post( "' . Url::to(['//task/givepreview', 'id' => '']) . '"+$(this).val(), function( data ) { $( "#givepreview" ).html( data ); }); '], 'pluginOptions' => ['tags' => true]]); ?> <?php echo Html::tag('br'); ?> <div class="panel panel-default"> <div class='panel-heading'>Текст задания</div> <div class='panel-body' id="givepreview" ><?php echo Markdown::process($model->task->text); ?> </div>
/** * @task control */ public function actionControl() { $searchModel = new TaskSearch(); $query = Task::find()->where(['task.teacher_id' => Yii::$app->user->identity->teacher->id]); $dataProvider = $searchModel->search(Yii::$app->request->get(), $query); return $this->render('control', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }