<?php

namespace modules\custom\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use modules\forms\models\Forms;

/**
 * dt143search represents the model behind the search form about `\modules\custom\models\Dt143`.
 */
class Dt143search extends Forms
{
    /**
     * @inheritdoc
     */
    public function rules(): array
    {
        return [
            [['id', 'created_by', 'updated_by', 'deleted_by', 'actid', 'relatedid', 'status', ], 'safe'],
            [['created_at', 'updated_at', 'deleted_at', 'jobno',], '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 = Forms::find()
        ->where(['form' => 'dt143'])
        ->andWhere(['!=','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,
        ]);

        $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', 'status', $this->status]);

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

        $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', 'status', $this->status])
            ->andFilterWhere(['like', 'padno', $this->padno])
            ->andFilterWhere(['like', 'signature', $this->signature])
            ->andFilterWhere(['like', 'question1', $this->question1])
            ->andFilterWhere(['like', 'question2', $this->question2])
            ->andFilterWhere(['like', 'question3', $this->question3])
            ->andFilterWhere(['like', 'question4', $this->question4])
            ->andFilterWhere(['like', 'question5', $this->question5])
            ->andFilterWhere(['like', 'question6', $this->question6])
            ->andFilterWhere(['like', 'question7', $this->question7])
            ->andFilterWhere(['like', 'question8', $this->question8])
            ->andFilterWhere(['like', 'question9', $this->question9])
            ->andFilterWhere(['like', 'question10', $this->question10])
            ->andFilterWhere(['like', 'question12', $this->question12])
            ->andFilterWhere(['like', 'question13', $this->question13])
            ->andFilterWhere(['like', 'question14', $this->question14])
            ->andFilterWhere(['like', 'question15', $this->question15])
            ->andFilterWhere(['like', 'question16', $this->question16])
            ->andFilterWhere(['like', 'question17', $this->question17])
            ->andFilterWhere(['like', 'question18', $this->question18])
            ->andFilterWhere(['like', 'question19', $this->question19])
            ->andFilterWhere(['like', 'question20', $this->question20]);

        return $dataProvider;
    }
}
