<?php

namespace modules\activities\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use modules\activities\models\Activitiesusers;

/**
 * activitiesusersSearch represents the model behind the search form about `frontend\models\Activitiesusers`.
 */
class ActivitiesusersSearch extends Activitiesusers
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'actid', 'operativename', 'postcodefrom', 'postcodeto'], 'safe'],
            [['operativeid', 'distance', 'traveltime', 'shifttime', 'totaltime', 'created_at', 'created_by', 'updated_at', 'updated_by'], '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 = Activitiesusers::find()
			->where(['!=','deleted',1]);

        // 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([
            'operativeid' => $this->operativeid,
            'distance' => $this->distance,
            'traveltime' => $this->traveltime,
            'shifttime' => $this->shifttime,
            'totaltime' => $this->totaltime,
            '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', 'operativename', $this->operativename])
            ->andFilterWhere(['like', 'postcodefrom', $this->postcodefrom])
            ->andFilterWhere(['like', 'postcodeto', $this->postcodeto]);

        return $dataProvider;
    }

    public function deleted($params)
    {
        $query = Activitiesusers::find()
		->where(['activitiesusers.deleted' => true]);

        // 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([
            'operativeid' => $this->operativeid,
            'distance' => $this->distance,
            'traveltime' => $this->traveltime,
            'shifttime' => $this->shifttime,
            'totaltime' => $this->totaltime,
            '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', 'operativename', $this->operativename])
            ->andFilterWhere(['like', 'postcodefrom', $this->postcodefrom])
            ->andFilterWhere(['like', 'postcodeto', $this->postcodeto]);

        return $dataProvider;
    }
}
