Exemple #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVideos()
 {
     return $this->hasMany(ProductVideo::className(), ['product_id' => 'id']);
 }
 /**
  * Users which have 'updateOwnProduct' permission can delete video only from Product models that have been created by their.
  * Users which have 'updateProduct' permission can delete video from all Product models.
  *
  * @param integer $id
  * @param integer $languageId
  * @return mixed
  * @throws ForbiddenHttpException
  */
 public function actionDeleteVideo($id, $languageId)
 {
     if (!empty($id)) {
         $video = ProductVideo::findOne($id);
         $product = Product::findOne($video->product_id);
         if (\Yii::$app->user->can('updateProduct', ['productOwner' => $product->owner])) {
             if ($video->resource == 'videofile') {
                 $dir = Yii::getAlias('@frontend/web/video');
                 unlink($dir . '/' . $video->file_name);
             }
             ProductVideo::deleteAll(['id' => $id]);
             return $this->renderPartial('add-video', ['product' => $product, 'selectedLanguage' => Language::findOne($languageId), 'video_form' => new ProductVideo(), 'video_form_upload' => new ProductVideoForm(), 'videos' => ProductVideo::find()->where(['product_id' => $product->id])->all()]);
         } else {
             throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to do this action.'));
         }
     }
     return false;
 }