| Current Path : /var/www/html/dosmv2/backend/modules/contentVideo/models/ |
| Current File : /var/www/html/dosmv2/backend/modules/contentVideo/models/ContentVideoSearch.php |
<?php
namespace backend\modules\contentVideo\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\contentVideo\models\ContentVideo;
use Yii;
/**
* ContentVideoSearch represents the model behind the search form of `backend\modules\contentVideo\models\ContentVideo`.
*/
class ContentVideoSearch extends ContentVideo {
public $video_title;
public $video_url;
public $video_location;
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['video_id', 'created_by', 'updated_by', 'video_sorting'], 'integer'],
[['video_date', 'video_category', 'video_status', 'video_url', 'video_page', 'created_at', 'updated_at', 'video_title',
'video_content', 'video_url', 'video_location', 'video_source', 'video_code'], '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()
->innerJoin('content_video_translation', 'content_video_translation.video_translation_parent_id=content_video.video_id')
->where(['=', 'content_video_translation.video_translation_main', '1']);
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10,]]);
$dataProvider->setSort(['defaultOrder' => ['video_date' => SORT_DESC]]);
$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(['LIKE', 'video_translation_title', $this->video_title]);
$query->andFilterWhere(['=', 'video_status', $this->video_status]);
$query->andFilterWhere(['LIKE', 'video_date', $this->video_date]);
$query->andFilterWhere(['LIKE', 'video_source', $this->video_source]);
$query->andFilterWhere(['LIKE', 'video_code', $this->video_code]);
if (!empty($this->video_page))
$query->andFilterWhere(['LIKE', 'video_page', '"' . $this->video_page . '"']);
if (\backend\modules\mimin\models\User::userrole() == 'admin-branch') {
$query->andWhere(['LIKE', 'video_page', '"' . Yii::$app->user->identity->branch . '"']);
}
return $dataProvider;
}
}