Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * Updates an existing Video model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //VideoTag::deleteAll(['video_id' => $model->id]);
         $tags = Yii::$app->request->post('Video')['tags'];
         foreach ($tags as &$arr) {
             $tagvid = new VideoTag();
             $tagvid->created_by = Yii::$app->user->id;
             $tagvid->tag_id = $arr;
             $tagvid->video_id = $model->id;
             $tagvid->save();
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Esempio n. 3
0
 /**
  * @return ActiveQuery
  */
 public function getVideoTags()
 {
     return $this->hasMany(VideoTag::className(), ['tag_id' => 'id']);
 }