/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Todo::find(); $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, 'project_id' => $this->project_id, 'user_id' => $this->user_id, 'author_id' => $this->author_id, 'status' => $this->status, 'type' => $this->type, 'date_start' => $this->date_start, 'created' => $this->created]); $query->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
use deka6pb\simpleTodo\models\Todo; use dosamigos\datepicker\DatePicker; use yii\helpers\Html; use yii\grid\GridView; use yii\widgets\Pjax; /* @var $this yii\web\View */ /* @var $searchModel backend\modules\simpletodo\models\Todo */ /* @var $dataProvider yii\data\ActiveDataProvider */ ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'rowOptions' => function ($model) { if ($model->status == $model::STATUS_CONTINUES && date($model::FORMAT_DATETIME) > $model->date_start) { return ['class' => 'danger']; } }, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn', 'checkboxOptions' => function ($model, $key, $index, $column) { return ['data-id' => $model->id, 'class' => "disabled todo_status", 'checked' => $model->status == $model::STATUS_FINISHED ? true : false]; }], ['attribute' => 'text:ntext', 'format' => 'raw', 'value' => function ($model) { return $model->status == $model::STATUS_FINISHED ? '<span class="completed">' . $model->text . '</span>' : $model->text; }], ['attribute' => 'type', 'filter' => Html::activeDropDownList($searchModel, 'status', Todo::getTypeAliases(), ['class' => 'form-control', 'prompt' => '--']), 'value' => function ($model) { return $model->getType(); }], ['attribute' => 'user_id', 'value' => function ($model) { return $model->getUserName(); }], ['attribute' => 'date_start', 'format' => ['date', 'php:Y-m-d H:i'], 'options' => ['width' => '200'], 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'date_start', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']])], 'duration_minute', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{check}', 'buttons' => ["check" => function ($url, $model) { if ($model->status == $model::STATUS_CONTINUES) { return Html::a('<span class="glyphicon glyphicon-ok"></span>', $url, ['title' => Yii::t('app', 'Check'), 'data-pjax' => '1', 'data-toggle-active' => $model->id]); } }]]]]); ?>
?> <?php echo $form->field($model, 'project_id')->dropDownList(Project::getProjectsList(), ['prompt' => '']); ?> <?php echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(User::find()->all(), 'id', 'username'), ['prompt' => '']); ?> <?php echo $form->field($model, 'text')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'type')->dropDownList(Todo::getTypeAliases(), ['prompt' => '']); ?> <?php echo $form->field($model, 'date_start')->widget(DatePicker::className(), ['inline' => true, 'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>', 'clientOptions' => ['autoclose' => false, 'format' => Todo::FORMAT_DATE_SHOW]]); ?> <?php echo $form->field($model, 'duration_minute')->textInput(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getTodos() { return $this->hasMany(Todo::className(), ['project_id' => 'id']); }
/** * Finds the Todo model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Todo the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Todo::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }