<?php

namespace modules\custom\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use modules\custom\models\Dt078be;

/**
 * dt078beSearch represents the model behind the search form about `\modules\custom\models\Dt078be`.
 */
class Dt078beSearch extends Dt078be
{
    /**
     * @inheritdoc
     */
    public function rules() : array
    {
        return [
            [['id', 'created_by', 'updated_by', 'deleted_by', 'actid', 'relatedid', 'name', 'signednameop', 'signednamesup', 'status', 'padno', 'natindno', 'reason', 'medication', 'advice', 'opsigned', 'supsigned'], 'safe'],
            [['created_at', 'updated_at', 'deleted_at', 'jobno', 'date', 'selfpescribed', 'pescribed', 'maywork', 'accompanied', 'safety', 'stooddown'], 'integer'],
        ];
    }

    /**
     * @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 = Dt078be::find()
        ->where(['!=','status','deleted']);

        // 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([
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'deleted_at' => $this->deleted_at,
            'jobno' => $this->jobno,
            'date' => $this->date,
            'selfpescribed' => $this->selfpescribed,
            'pescribed' => $this->pescribed,
            'maywork' => $this->maywork,
            'accompanied' => $this->accompanied,
            'safety' => $this->safety,
            'stooddown' => $this->stooddown,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by])
            ->andFilterWhere(['like', 'deleted_by', $this->deleted_by])
            ->andFilterWhere(['like', 'actid', $this->actid])
            ->andFilterWhere(['like', 'relatedid', $this->relatedid])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'signednameop', $this->signednameop])
            ->andFilterWhere(['like', 'signednamesup', $this->signednamesup])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'natindno', $this->natindno])
            ->andFilterWhere(['like', 'reason', $this->reason])
            ->andFilterWhere(['like', 'medication', $this->medication])
            ->andFilterWhere(['like', 'advice', $this->advice])
            ->andFilterWhere(['like', 'opsigned', $this->opsigned])
            ->andFilterWhere(['like', 'supsigned', $this->supsigned]);

        return $dataProvider;
    }
    public function deleted($params)
    {
        $query = Dt078be::find()
        ->where(['=','status','deleted']);

        // 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([
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'deleted_at' => $this->deleted_at,
            'jobno' => $this->jobno,
            'date' => $this->date,
            'selfpescribed' => $this->selfpescribed,
            'pescribed' => $this->pescribed,
            'maywork' => $this->maywork,
            'accompanied' => $this->accompanied,
            'safety' => $this->safety,
            'stooddown' => $this->stooddown,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by])
            ->andFilterWhere(['like', 'deleted_by', $this->deleted_by])
            ->andFilterWhere(['like', 'actid', $this->actid])
            ->andFilterWhere(['like', 'relatedid', $this->relatedid])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'signednameop', $this->signednameop])
            ->andFilterWhere(['like', 'signednamesup', $this->signednamesup])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'natindno', $this->natindno])
            ->andFilterWhere(['like', 'reason', $this->reason])
            ->andFilterWhere(['like', 'medication', $this->medication])
            ->andFilterWhere(['like', 'advice', $this->advice])
            ->andFilterWhere(['like', 'opsigned', $this->opsigned])
            ->andFilterWhere(['like', 'supsigned', $this->supsigned]);

        return $dataProvider;
    }
}
