<?php

namespace app\models;

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

/**
 * ArtincenmasterSearch represents the model behind the search form about `app\models\Artincenmaster`.
 */
class ArtincenmasterSearch extends Artincenmaster
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['art_inc_id', 'create_time', 'create_user', 'update_time', 'update_user', 'record_date'], 'integer'],
            [['art_inc_survey', 'art_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 = Artincenmaster::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([
            'art_inc_id' => $this->art_inc_id,
            'art_inc_visitdate' => $this->art_inc_visitdate,
            'art_inc_q1' => $this->art_inc_q1,
            'art_inc_q2' => $this->art_inc_q2,
            'art_inc_q3' => $this->art_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', 'art_inc_survey', $this->art_inc_survey])
            ->andFilterWhere(['like', 'art_inc_part_id', $this->art_inc_part_id])
            ->andFilterWhere(['like', 'art_inc_q4', $this->art_inc_q4])
            ->andFilterWhere(['like', 'status', $this->status]);

        return $dataProvider;
    }
}
