<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Preartincenmaster;

/**
 * PreartincenmasterSearch represents the model behind the search form about `app\models\Preartincenmaster`.
 */
class PreartincenmasterSearch extends Preartincenmaster
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['preart_inc_id',  'create_time', 'create_user', 'update_time', 'update_user', 'record_date'], 'integer'],
            [['preart_inc_survey', 'preart_inc_part_id', 'status'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Preartincenmaster::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
			'sort'=>[
                'defaultOrder'=>['record_date'=> SORT_DESC],
			],
        ]);

        $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;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'preart_inc_id' => $this->preart_inc_id,
            'preart_inc_visitdate' => $this->preart_inc_visitdate,
            'preart_inc_q1' => $this->preart_inc_q1,
            'preart_inc_q2' => $this->preart_inc_q2,
            'preart_inc_q3' => $this->preart_inc_q3,
            'create_time' => $this->create_time,
            'create_user' => $this->create_user,
            'update_time' => $this->update_time,
            'update_user' => $this->update_user,
            'record_date' => $this->record_date,
        ]);

        $query->andFilterWhere(['like', 'preart_inc_survey', $this->preart_inc_survey])
            ->andFilterWhere(['like', 'preart_inc_part_id', $this->preart_inc_part_id])
            ->andFilterWhere(['like', 'preart_inc_q4', $this->preart_inc_q4])
            ->andFilterWhere(['like', 'status', $this->status]);

        return $dataProvider;
    }
}
