<?php

namespace frontend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use frontend\models\Option;

/**
 * OptionSearch represents the model behind the search form about `frontend\models\Option`.
 */
class OptionSearch extends Option
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['option_id', 'model_id', 'option_pid'], 'integer'],
            [['model', 'name', 'template'], '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 = Option::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
		$data = [
			'OptionSearch' => [
				'model' => 'Main'
			]
		];
		
        $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->andWhere(['option_pid' => null]);
        
        $query->andFilterWhere([
            'option_id' => $this->option_id,
            'model_id' => $this->model_id,
            'option_pid' => $this->option_pid,
        ]);
		
        $query->andFilterWhere(['like', 'model', $this->model])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'template', $this->template]);
        

        return $dataProvider;
    }
}
