<?php

namespace backend\models;

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

/**
 * Frapl01Search represents the model behind the search form of `backend\models\Frapl01`.
 */
class Frapl01Search extends Frapl01
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ASESMEN_UUID', 'FRAPL01_UUID', 'FRAPL01_LSP_REKOMENDASI', 'FRAPL01_LSP_CATATAN', 'FRAPL01_LSP_USERNAME', 'FRAPL01_LSP_TGL', 'FRAPL01_LSP_TTD', 'FRAPL01_USER_USERNAME', 'FRAPL01_USER_TGL', 'FRAPL01_USER_TTD'], '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 = Frapl01::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([
            'FRAPL01_LSP_TGL' => $this->FRAPL01_LSP_TGL,
            'FRAPL01_USER_TGL' => $this->FRAPL01_USER_TGL,
        ]);

        $query->andFilterWhere(['like', 'ASESMEN_UUID', $this->ASESMEN_UUID])
            ->andFilterWhere(['like', 'FRAPL01_UUID', $this->FRAPL01_UUID])
            ->andFilterWhere(['like', 'FRAPL01_LSP_REKOMENDASI', $this->FRAPL01_LSP_REKOMENDASI])
            ->andFilterWhere(['like', 'FRAPL01_LSP_CATATAN', $this->FRAPL01_LSP_CATATAN])
            ->andFilterWhere(['like', 'FRAPL01_LSP_USERNAME', $this->FRAPL01_LSP_USERNAME])
            ->andFilterWhere(['like', 'FRAPL01_LSP_TTD', $this->FRAPL01_LSP_TTD])
            ->andFilterWhere(['like', 'FRAPL01_USER_USERNAME', $this->FRAPL01_USER_USERNAME])
            ->andFilterWhere(['like', 'FRAPL01_USER_TTD', $this->FRAPL01_USER_TTD]);

        return $dataProvider;
    }
}
