<?php

namespace app\models;

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

/**
 * TrainingRequestSearchs represents the model behind the search form of `app\models\TrainingRequest`.
 */
class TrainingRequestsSearch extends TrainingRequests
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'phone', 'mobile', 'alternative_phone_number'], 'integer'],
            [['full_name', 'full_name_english', 'mother_name', 'gender', 'residence_place', 'educational_degree', 'university_name', 'faculty', 'year_of_study', 'university_training_request', 'personal_photo', 'identity', 'training_request_status', 'create_date', 'serial_number'], '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 = TrainingRequests::find();

        // add conditions that should always apply here

        $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;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'phone' => $this->phone,
            'mobile' => $this->mobile,
            'alternative_phone_number' => $this->alternative_phone_number,
            'create_date' => $this->create_date,
        ]);

        $query->andFilterWhere(['like', 'full_name', $this->full_name])
            ->andFilterWhere(['like', 'full_name_english', $this->full_name_english])
            ->andFilterWhere(['like', 'mother_name', $this->mother_name])
            ->andFilterWhere(['like', 'gender', $this->gender])
            ->andFilterWhere(['like', 'residence_place', $this->residence_place])
            ->andFilterWhere(['like', 'educational_degree', $this->educational_degree])
            ->andFilterWhere(['like', 'university_name', $this->university_name])
            ->andFilterWhere(['like', 'faculty', $this->faculty])
            ->andFilterWhere(['like', 'year_of_study', $this->year_of_study])
            ->andFilterWhere(['like', 'university_training_request', $this->university_training_request])
            ->andFilterWhere(['like', 'personal_photo', $this->personal_photo])
            ->andFilterWhere(['like', 'identity', $this->identity])
            ->andFilterWhere(['like', 'training_request_status', $this->training_request_status])
            ->andFilterWhere(['like', 'serial_number', $this->serial_number]);

        return $dataProvider;
    }
}
