public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'only' => ['index', 'view', 'create', 'update', 'delete', 'actions'], 'rules' => [['actions' => ['index', 'view', 'create', 'update', 'delete', 'actions'], 'allow' => true, 'roles' => ['@']]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post']]], ['class' => 'yii\\filters\\PageCache', 'only' => ['index'], 'duration' => 60, 'variations' => [\Yii::$app->language], 'dependency' => ['class' => 'yii\\caching\\DbDependency', 'sql' => 'SELECT COUNT(*) FROM ' . Video::tableName()]], ['class' => 'yii\\filters\\HttpCache', 'only' => ['index'], 'lastModified' => function ($action, $params) { $q = new \yii\db\Query(); $res = $q->from('video')->max('create_date'); return strtotime($res); }]]; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Video::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); $_column = [Video::tableName() . '.id', Video::tableName() . '.video_url', Video::tableName() . '.title_' . Yii::$app->language, Video::tableName() . '.description_' . Yii::$app->language, Video::tableName() . '.create_date', Video::tableName() . '.created_by', Video::tableName() . '.status']; $query->joinWith(['createdBy']); $query->select($_column)->distinct(); if ($this->filter) { $query->joinWith(['videoTags']); } $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; } $query->andFilterWhere(['id' => $this->id, 'create_date' => $this->create_date]); $query->andFilterWhere(['like', 'search', $this->search])->andFilterWhere(['like', 'video_code', $this->video_code])->andFilterWhere(['like', 'video_url', $this->video_url])->andFilterWhere(['like', 'title_ar', $this->title_ar])->andFilterWhere(['like', 'title_en', $this->title_en])->andFilterWhere(['like', 'description_ar', $this->description_ar])->andFilterWhere(['like', 'description_en', $this->description_en])->andFilterWhere(['like', 'status', $this->status]); if ($this->filter) { $query->andFilterWhere(['IN', VideoTag::tableName() . '.tag_id', $this->video_tag]); } $query->orderBy('create_date DESC'); return $dataProvider; }