<?php

namespace api\modules\prolab\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\VirtualLabMappingLog;

/**
 * VirtualLabMappingLogSearch represents the model behind the search form of `common\models\VirtualLabMappingLog`.
 */
class VirtualLabMappingLogSearch extends VirtualLabMappingLog
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['labno', 'RiaHDocID', 'patname', 'pathn', 'patward', 'status', 'pattitle', 'custid', 'RiaHDocDate', 'patage', 'filename', 'patsex', 'RiaHDocID_PRE', 'RiaHDocDate_PRE', 'birthday', 'DOB', 'reqdate'], '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 = VirtualLabMappingLog::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,
            'RiaHDocDate' => $this->RiaHDocDate,
            'RiaHDocDate_PRE' => $this->RiaHDocDate_PRE,
            'birthday' => $this->birthday,
        ]);

        $query->andFilterWhere(['like', 'labno', $this->labno])
            ->andFilterWhere(['like', 'RiaHDocID', $this->RiaHDocID])
            ->andFilterWhere(['like', 'patname', $this->patname])
            ->andFilterWhere(['like', 'pathn', $this->pathn])
            ->andFilterWhere(['like', 'patward', $this->patward])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'pattitle', $this->pattitle])
            ->andFilterWhere(['like', 'custid', $this->custid])
            ->andFilterWhere(['like', 'patage', $this->patage])
            ->andFilterWhere(['like', 'filename', $this->filename])
            ->andFilterWhere(['like', 'patsex', $this->patsex])
            ->andFilterWhere(['like', 'RiaHDocID_PRE', $this->RiaHDocID_PRE])
            ->andFilterWhere(['like', 'DOB', $this->DOB])
            ->andFilterWhere(['like', 'reqdate', $this->reqdate]);

        return $dataProvider;
    }
}
