<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\MasterSkema;

/**
 * MasterSkemaSearch represents the model behind the search form of `backend\models\MasterSkema`.
 */
class MasterSkemaSearch extends MasterSkema
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['SKEMA_UUID', 'SKEMA_NOMOR', 'SKEMA_NAMA', 'SKEMA_JENIS', 'CREATED', 'USERNAME'], 'safe'],
            [['SKEMA_BIAYA'], 'number'],
        ];
    }

    /**
     * {@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
     * @param string|null $formName Form name to be used into `->load()` method.
     *
     * @return ActiveDataProvider
     */
    public function search($params, $formName = null)
    {
        $query = MasterSkema::find();

        // add conditions that should always apply here

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

        $this->load($params, $formName);

        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([
            'SKEMA_BIAYA' => $this->SKEMA_BIAYA,
            'CREATED' => $this->CREATED,
        ]);

        $query->andFilterWhere(['like', 'SKEMA_UUID', $this->SKEMA_UUID])
            ->andFilterWhere(['like', 'SKEMA_NOMOR', $this->SKEMA_NOMOR])
            ->andFilterWhere(['like', 'SKEMA_NAMA', $this->SKEMA_NAMA])
            ->andFilterWhere(['like', 'SKEMA_JENIS', $this->SKEMA_JENIS])
            ->andFilterWhere(['like', 'USERNAME', $this->USERNAME]);

        return $dataProvider;
    }
}
