Your IP : 216.73.216.124


Current Path : /var/www/html/chatbot/backend/models/
Upload File :
Current File : /var/www/html/chatbot/backend/models/EventSearch.php

<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Event;

/**
 * EventSearch represents the model behind the search form about `backend\models\Event`.
 */
class EventSearch extends Event {

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['id', 'repeat_for', 'link_id'], 'integer'],
            [['title', 'start_date', 'end_date', 'start_time', 'end_time', 'cat_id', 'description', 'location', 'create_by', 'create_date', 'event_type', 'view_group', 'reminder', 'repeat', 'sms_reminder', 'reminder2', 'update_dt'], 'safe'],
        ];
    }

    /**
     * @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 = Event::find();

        // 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([
            'id' => $this->id,
            'start_date' => $this->start_date,
            'end_date' => $this->end_date,
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'create_date' => $this->create_date,
            'reminder' => $this->reminder,
            'repeat_for' => $this->repeat_for,
            'link_id' => $this->link_id,
            'sms_reminder' => $this->sms_reminder,
            'update_dt' => $this->update_dt,
        ]);

        $query->andFilterWhere(['like', 'title', $this->title])
                ->andFilterWhere(['like', 'cat_id', $this->cat_id])
                ->andFilterWhere(['like', 'description', $this->description])
                ->andFilterWhere(['like', 'location', $this->location])
                ->andFilterWhere(['like', 'create_by', $this->create_by])
                ->andFilterWhere(['like', 'event_type', $this->event_type])
                ->andFilterWhere(['like', 'view_group', $this->view_group])
                ->andFilterWhere(['like', 'repeat', $this->repeat])
                ->andFilterWhere(['like', 'reminder2', $this->reminder2]);

        return $dataProvider;
    }

    public function searchToday($params) {
//        $query = Event::find()
//                ->where("start_date<='" . date("Y-m-d") . "' AND end_date>='".date("Y-m-d")."'");
        
        $query = Event::find();

        // 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([
            'id' => $this->id,
            'start_date' => $this->start_date,
            'end_date' => $this->end_date,
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'create_date' => $this->create_date,
            'reminder' => $this->reminder,
            'repeat_for' => $this->repeat_for,
            'link_id' => $this->link_id,
            'sms_reminder' => $this->sms_reminder,
            'update_dt' => $this->update_dt,
        ]);

        $query->andFilterWhere(['like', 'title', $this->title])
                ->andFilterWhere(['like', 'cat_id', $this->cat_id])
                ->andFilterWhere(['like', 'description', $this->description])
                ->andFilterWhere(['like', 'location', $this->location])
                ->andFilterWhere(['like', 'create_by', $this->create_by])
                ->andFilterWhere(['like', 'event_type', $this->event_type])
                ->andFilterWhere(['like', 'view_group', $this->view_group])
                ->andFilterWhere(['like', 'repeat', $this->repeat])
                ->andFilterWhere(['like', 'reminder2', $this->reminder2]);

        return $dataProvider;
    }

    public function searchDiary($params) {
        $query = Event::find()->
                where("create_by='" . Yii::$app->user->identity->staff->id . "'");

        // 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([
            'id' => $this->id,
            'start_date' => $this->start_date,
            'end_date' => $this->end_date,
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'create_date' => $this->create_date,
            'reminder' => $this->reminder,
            'repeat_for' => $this->repeat_for,
            'link_id' => $this->link_id,
            'sms_reminder' => $this->sms_reminder,
            'update_dt' => $this->update_dt,
        ]);

        $query->andFilterWhere(['like', 'title', $this->title])
                ->andFilterWhere(['like', 'cat_id', $this->cat_id])
                ->andFilterWhere(['like', 'description', $this->description])
                ->andFilterWhere(['like', 'location', $this->location])
                ->andFilterWhere(['like', 'create_by', $this->create_by])
                ->andFilterWhere(['like', 'event_type', $this->event_type])
                ->andFilterWhere(['like', 'view_group', $this->view_group])
                ->andFilterWhere(['like', 'repeat', $this->repeat])
                ->andFilterWhere(['like', 'reminder2', $this->reminder2]);

        return $dataProvider;
    }

}