<?php

namespace modules\cors\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use modules\cors\models\Sightcheckbe;

/**
 * fsightcheckbeSearch represents the model behind the search form about `\backend\models\Sightcheckbe`.
 */
class SightcheckbeSearch extends sightcheckbe
{
    /**
     * @inheritdoc
     */
    public function rules() : array
    {
        return [
            [['id', 'created_by', 'updated_by', 'deleted_by', 'actid', 'relatedid', 'employee', 'tester', 'status', 'padno', 'position', 'wearsglasses', 'type', 'location', 'registration', 'registariongiven', 'result'], 'safe'],
            [['created_at', 'updated_at', 'deleted_at', 'jobno', 'date'], '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 = sightcheckbe::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,
        ]);

        $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', 'employee', $this->employee])
            ->andFilterWhere(['like', 'tester', $this->tester])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'position', $this->position])
            ->andFilterWhere(['like', 'wearsglasses', $this->wearsglasses])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'location', $this->location])
            ->andFilterWhere(['like', 'registration', $this->registration])
            ->andFilterWhere(['like', 'registariongiven', $this->registariongiven])
            ->andFilterWhere(['like', 'result', $this->result]);

        return $dataProvider;
    }
    public function deleted($params)
    {
        $query = sightcheckbe::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,
        ]);

        $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', 'employee', $this->employee])
            ->andFilterWhere(['like', 'tester', $this->tester])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'position', $this->position])
            ->andFilterWhere(['like', 'wearsglasses', $this->wearsglasses])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'location', $this->location])
            ->andFilterWhere(['like', 'registration', $this->registration])
            ->andFilterWhere(['like', 'registariongiven', $this->registariongiven])
            ->andFilterWhere(['like', 'result', $this->result]);

        return $dataProvider;
    }
}
