<?php

namespace app\models;

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

/**
 * MobilenumbersSearch represents the model behind the search form about `app\models\Mobilenumbers`.
 */
class MobilenumbersSearch extends Mobilenumbers
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['mobile_id', 'record_date'], 'integer'],
            [['mobile_part_id', 'mobile_q1'], '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 = Mobilenumbers::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        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([
            'mobile_id' => $this->mobile_id,
            'record_date' => $this->record_date,
        ]);

        $query->andFilterWhere(['like', 'mobile_part_id', $this->mobile_part_id])
            ->andFilterWhere(['like', 'mobile_q1', $this->mobile_q1]);

        return $dataProvider;
    }
}