<?php

namespace backend\models;

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

/**
 * Frapl02Search represents the model behind the search form of `backend\models\Frapl02`.
 */
class Frapl02Search extends Frapl02
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ASESMEN_UUID', 'FRAPL02_UUID', 'FRAPL02_LSP_REKOMENDASI', 'FRAPL02_LSP_USERNAME', 'FRAPL02_NOREG', 'FRAPL02_LSP_TGL', 'FRAPL02_LSP_TTD', 'FRAPL02_USER_USERNAME', 'FRAPL02_USER_TGL', 'FRAPL02_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 = Frapl02::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([
            'FRAPL02_LSP_TGL' => $this->FRAPL02_LSP_TGL,
            'FRAPL02_USER_TGL' => $this->FRAPL02_USER_TGL,
        ]);

        $query->andFilterWhere(['like', 'ASESMEN_UUID', $this->ASESMEN_UUID])
            ->andFilterWhere(['like', 'FRAPL02_UUID', $this->FRAPL02_UUID])
            ->andFilterWhere(['like', 'FRAPL02_LSP_REKOMENDASI', $this->FRAPL02_LSP_REKOMENDASI])
            ->andFilterWhere(['like', 'FRAPL02_LSP_USERNAME', $this->FRAPL02_LSP_USERNAME])
            ->andFilterWhere(['like', 'FRAPL02_NOREG', $this->FRAPL02_NOREG])
            ->andFilterWhere(['like', 'FRAPL02_LSP_TTD', $this->FRAPL02_LSP_TTD])
            ->andFilterWhere(['like', 'FRAPL02_USER_USERNAME', $this->FRAPL02_USER_USERNAME])
            ->andFilterWhere(['like', 'FRAPL02_USER_TTD', $this->FRAPL02_USER_TTD]);

        return $dataProvider;
    }
}
