<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Regngoupdate;
use app\base\Converter;

/**
 * RegngoupdateSearch represents the model behind the search form about `app\models\Regngoupdate`.
 */
class RegngoupdateSearch extends Regngoupdate
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['corfrm_id', 'corfrm_q3', 'corfrm_q4', 'corfrm_q5', 'corfrm_q6', 'corfrm_q7', 'corfrm_q8', 'corfrm_q9', 'corfrm_q10', 'create_time', 'create_user', 'update_time', 'update_user'], 'integer'],
            [['corfrm_sid', 'corfrm_pid', 'corfrm_loc', 'corfrm_q1', 'corfrm_q2','corfrm_q11', 'corfrm_q12', 'corfrm_q13', 'corfrm_q14','status','icc_date','record_date'], '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 = Regngoupdate::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
			'sort'=>[
                'defaultOrder'=>['record_date'=> SORT_DESC],
            ],
        ]);
        if(empty($params))
            $params = Yii::$app->request->post();
        $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([
            'corfrm_id' => $this->corfrm_id,
            'corfrm_q3' => $this->corfrm_q3,
            'corfrm_q4' => $this->corfrm_q4,
            'corfrm_q5' => $this->corfrm_q5,
            'corfrm_q6' => $this->corfrm_q6,
            'corfrm_q7' => $this->corfrm_q7,
            'corfrm_q8' => $this->corfrm_q8,
            'corfrm_q9' => $this->corfrm_q9,
            'corfrm_q10' => $this->corfrm_q10,			
            'create_time' => $this->create_time,
            'create_user' => $this->create_user,
            'update_time' => $this->update_time,
            'update_user' => $this->update_user,
            'record_date' => Converter::toUnixTimeformat($this->record_date),
        ]);

        $query->andFilterWhere(['like', 'corfrm_sid', $this->corfrm_sid])
            ->andFilterWhere(['like', 'corfrm_pid', $this->corfrm_pid])
            ->andFilterWhere(['like', 'corfrm_loc', $this->corfrm_loc])
            ->andFilterWhere(['like', 'corfrm_q1', $this->corfrm_q1])
            ->andFilterWhere(['like', 'corfrm_q2', $this->corfrm_q2])
			->andFilterWhere(['like', 'corfrm_q11', $this->corfrm_q11])
			->andFilterWhere(['like', 'corfrm_q12', $this->corfrm_q12])
            ->andFilterWhere(['like', 'corfrm_q13', $this->corfrm_q13])
			->andFilterWhere(['like', 'corfrm_q14', $this->corfrm_q14])
            ->andFilterWhere(['like', 'status', $this->status]);

        return $dataProvider;
    }
}