Your IP : 216.73.216.79


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

<?php

namespace backend\models;

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

/**
 * BanciVideoSearch represents the model behind the search form of `backend\models\BanciVideo`.
 */
class ContentVideoSearch extends ContentVideo
{   
    public $year;
    public $month;
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['content_video_id', 'content_video_status'], 'integer'],
            [['content_video_title', 'content_video_title_en', 'content_video_description', 'content_video_description_en', 'created_at', 'created_by', 'updated_at', 'updated_by','content_video_featured'], '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 = ContentVideo::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([
            'content_video_id' => $this->content_video_id,
            'content_video_status' => $this->content_video_status,
            // 'created_at' => $this->created_at,
            // 'updated_at' => $this->updated_at,
        ]);

        if (!empty($this->year)) {
            $query->andFilterWhere(['YEAR(created_at)' => $this->year]);
        }

        if (!empty($this->month)) {
            $query->andFilterWhere(['MONTH(created_at)' => $this->month]);
        }

        if (!empty($this->content_video_status)) {
            $query->andFilterWhere(['content_video_status' => $this->content_video_status]);
        }

        $query->andFilterWhere(['like', 'content_video_title', $this->content_video_title])
            ->andFilterWhere(['like', 'content_video_title_en', $this->content_video_title_en])
            ->andFilterWhere(['like', 'content_video_description', $this->content_video_description])
            ->andFilterWhere(['like', 'content_video_description_en', $this->content_video_description_en])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by]);

        return $dataProvider;
    }
}