<?php

namespace modules\forms\models;

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

/**
 * dt198Search represents the model behind the search form about `frontend\models\Dt198`.
 */
class Formssearch extends Forms
{
    /**
     * @inheritdoc
     */
    public function rules(): array {
        return [
            [['id', 'actid', 'location', 'jobno', 'updated_by', 'created_by', 'form' ], 'safe'],
            [['created_at', 'updated_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 = parent::find()
		->where(['or', ['not', ['status' => 'Deleted']], ['is', 'status', null]])
		->orderby(['created_at' => SORT_DESC]);

        // add conditions that should always apply here
        $this->load($params);
        $query->andFilterWhere(['form' => $this->form]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);


        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,
            'created_by' => $this->created_by,
            'updated_at' => $this->updated_at,
            'updated_by' => $this->updated_by,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'actid', $this->actid])
            ->andFilterWhere(['like', 'jobno', $this->jobno]);

        return $dataProvider;
    }
    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function actsearch($params) {
        $actid = yii::$app->request->get('id');
        $query = parent::find()
		->where(['actid' => $actid])
		->andWhere(['or', ['not', ['status' => 'Deleted']], ['is', 'status', null]])
		->orderby(['created_at' => SORT_DESC]);

        // add conditions that should always apply here
        $this->load($params);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);


        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,
            'created_by' => $this->created_by,
            'updated_at' => $this->updated_at,
            'updated_by' => $this->updated_by,
        ]);

        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'actid', $this->actid])
            ->andFilterWhere(['like', 'jobno', $this->jobno]);

        return $dataProvider;
    }
}
