<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Language;

/**
 * LanguageSearch represents the model behind the search form about `backend\models\Language`.
 */
class LanguageSearch extends Language
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['language_id'], 'integer'],
            [['language_code', 'language_name'], 'safe'],
            [['is_default', 'status'], 'boolean'],
        ];
    }

    /**
     * @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 = Language::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $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->andFilterWhere([
            'language_id' => $this->language_id,
            'is_default' => $this->is_default,
            'status' => $this->status,
        ]);

        $query->andFilterWhere(['like', 'language_code', $this->language_code])
            ->andFilterWhere(['like', 'language_name', $this->language_name])
            ->andWhere(['status' => '1'])
        	->andWhere(['>', 'language_id', '0']);

        return $dataProvider;
    }
    
    public function searchNew($params)
    {
        $query = Language::find();
    
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
    
        $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->andFilterWhere([
            'language_id' => $this->language_id,
            'is_default' => $this->is_default,
            'status' => $this->status,
        ]);
    
        $query->andFilterWhere(['like', 'language_code', $this->language_code])
        ->andFilterWhere(['like', 'language_name', $this->language_name])
        ->andWhere(['status' => '0']);
    
        return $dataProvider;
    }
}
