<?php

namespace backend\models;

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

/**
 * Frapl011bSearch represents the model behind the search form of `backend\models\Frapl011b`.
 */
class Frapl011bSearch extends Frapl011b
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['FRAPL01_UUID', 'FRAPL01_1B_UUID', 'FRAPL01_1B_INSTITUSI', 'FRAPL01_1B_JABATAN', 'FRAPL01_1B_ALAMAT', 'FRAPL01_1B_POS', 'FRAPL01_1B_TEL', 'FRAPL01_1B_FAX', 'FRAPL01_1B_EMAIL', 'CREATED', 'USERNAME'], '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
     * @param string|null $formName Form name to be used into `->load()` method.
     *
     * @return ActiveDataProvider
     */
    public function search($params, $formName = null)
    {
        $query = Frapl011b::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([
            'CREATED' => $this->CREATED,
        ]);

        $query->andFilterWhere(['like', 'FRAPL01_UUID', $this->FRAPL01_UUID])
            ->andFilterWhere(['like', 'FRAPL01_1B_UUID', $this->FRAPL01_1B_UUID])
            ->andFilterWhere(['like', 'FRAPL01_1B_INSTITUSI', $this->FRAPL01_1B_INSTITUSI])
            ->andFilterWhere(['like', 'FRAPL01_1B_JABATAN', $this->FRAPL01_1B_JABATAN])
            ->andFilterWhere(['like', 'FRAPL01_1B_ALAMAT', $this->FRAPL01_1B_ALAMAT])
            ->andFilterWhere(['like', 'FRAPL01_1B_POS', $this->FRAPL01_1B_POS])
            ->andFilterWhere(['like', 'FRAPL01_1B_TEL', $this->FRAPL01_1B_TEL])
            ->andFilterWhere(['like', 'FRAPL01_1B_FAX', $this->FRAPL01_1B_FAX])
            ->andFilterWhere(['like', 'FRAPL01_1B_EMAIL', $this->FRAPL01_1B_EMAIL])
            ->andFilterWhere(['like', 'USERNAME', $this->USERNAME]);

        return $dataProvider;
    }
}
