Пример #1
0
 /**
  * @inheritdoc
  */
 public function afterDelete()
 {
     Tagging::deleteAll(['taggable_type' => Tagging::TAGGABLE_VIDEO, 'taggable_id' => $this->id]);
     Relation::deleteAll(['relationable_type' => Relation::RELATIONABLE_VIDEO, 'relationable_id' => $this->id]);
     Comment::deleteAll(['commentable_type' => Comment::COMMENTABLE_VIDEO, 'commentable_id' => $this->id]);
     CommentCount::deleteAll(['commentable_type' => CommentCount::COMMENTABLE_VIDEO, 'commentable_id' => $this->id]);
     $assets = Asset::find()->where(['assetable_type' => Asset::ASSETABLE_VIDEO, 'assetable_id' => $this->id])->orWhere(['assetable_type' => Asset::ASSETABLE_VIDEOFILE, 'assetable_id' => $this->id])->all();
     foreach ($assets as $asset) {
         $asset->delete();
     }
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function afterDelete()
 {
     Relation::deleteAll(['parent_id' => $this->id]);
     Comment::deleteAll(['commentable_type' => Comment::COMMENTABLE_MATCH, 'commentable_id' => $this->id]);
     CommentCount::deleteAll(['commentable_type' => CommentCount::COMMENTABLE_MATCH, 'commentable_id' => $this->id]);
 }
 /**
  * Updates an existing VideoPost 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);
     $image = $model->getAsset();
     $tags = $model->getTags();
     $assets = $model->getAssets();
     $model->tags = [];
     foreach ($tags as $tag) {
         $model->tags[] = $tag->id;
     }
     $videoAsset = $model->getVideoAsset();
     $relation = Relation::find()->where(['relationable_id' => $model->id, 'relationable_type' => Relation::RELATIONABLE_VIDEO])->one();
     $matchModel = new \common\models\MatchSearch();
     $matchesList = [];
     if (!isset($relation)) {
         $relation = new Relation();
         $relation->relationable_type = Relation::RELATIONABLE_VIDEO;
     }
     if (!isset($relation->match)) {
         $matches = $matchModel::find()->orderBy(['date' => SORT_DESC])->limit(10)->all();
         foreach ($matches as $match) {
             $matchDate = date('d.m.Y', strtotime($match->date));
             $matchesList[$match->id] = $match->name . ' (' . $matchDate . ')';
         }
     } else {
         $matchModel->championship_id = $relation->match->championship_id;
         $matchModel->league_id = $relation->match->league_id;
         $matchModel->season_id = $relation->match->season_id;
         $matchModel->command_home_id = $relation->match->command_home_id;
         $matchModel->command_guest_id = $relation->match->command_guest_id;
         $matchDate = date('d.m.Y', strtotime($relation->match->date));
         $matchesList[$relation->match->id] = $relation->match->name . ' (' . $matchDate . ')';
     }
     $model->title = html_entity_decode($model->title);
     $model->content = html_entity_decode($model->content);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         // Set slug
         $model->slug = $model->genSlug($model->title);
         // Set image
         $uploadedFile = UploadedFile::getInstance($model, 'image');
         if ($uploadedFile) {
             // Remove old assets
             foreach ($assets as $asset) {
                 $asset->delete();
             }
             // Save origionals
             $asset = new Asset();
             $asset->assetable_type = Asset::ASSETABLE_VIDEO;
             $asset->assetable_id = $model->id;
             $asset->uploadedFile = $uploadedFile;
             $asset->saveAsset();
             // Save thumbnails
             $imageID = $asset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_VIDEO);
             foreach ($thumbnails as $thumbnail) {
                 $asset = new Asset();
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->assetable_type = Asset::ASSETABLE_VIDEO;
                 $asset->assetable_id = $model->id;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->saveAsset();
             }
         }
         // Save videofile
         $videoFile = UploadedFile::getInstance($model, 'video');
         if ($videoFile) {
             // Remove old assets
             $videoAsset->delete();
             // Save origionals
             $asset = new Asset();
             $asset->assetable_type = Asset::ASSETABLE_VIDEOFILE;
             $asset->assetable_id = $model->id;
             $asset->uploadedFile = $videoFile;
             $asset->saveVideoAsset();
         }
         $existingTags = [];
         // Remove tags
         foreach ($tags as $tag) {
             if (!is_array($model->tags) || !in_array($tag->id, $model->tags)) {
                 $model->removeTag($tag->id);
             } else {
                 $existingTags[] = $tag->id;
             }
         }
         // Adding new tags
         if (is_array($model->tags)) {
             foreach ($model->tags as $id) {
                 if (!in_array($id, $existingTags)) {
                     $model->addTag($id);
                 }
             }
         }
         $cached_tag_list = [];
         $newTags = $model->getTags();
         foreach ($newTags as $newTag) {
             $cached_tag_list[] = $newTag->name;
         }
         $model->cached_tag_list = implode(', ', $cached_tag_list);
         if (!isset($relation->relationable_id)) {
             $relation->relationable_id = $model->id;
             $relation->relationable_type = Relation::RELATIONABLE_VIDEO;
         }
         if ($relation->load(Yii::$app->request->post()) && $model->validate()) {
             if ($relation->parent_id != '' && is_array($relation->parent_id)) {
                 $relation->parent_id = $relation->parent_id[0];
             }
             if ($relation->parent_id && is_numeric($relation->parent_id)) {
                 $relation->save();
             } elseif (isset($relation->id)) {
                 $relation->delete();
             }
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'image' => $image, 'videoAsset' => $videoAsset, 'tags' => $tags, 'relation' => $relation, 'matchModel' => $matchModel, 'matchesList' => $matchesList]);
     }
 }
Пример #4
0
 /**
  * Updates an existing Album 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);
     $tags = $model->getTags();
     $coverImage = $model->getFrontendAsset(Asset::THUMBNAIL_BIG);
     $allAssets = $model->getAssets();
     $assets = [];
     foreach ($allAssets as $asset) {
         if ($asset->thumbnail == Asset::THUMBNAIL_BIG) {
             $assets[] = $asset;
         }
     }
     $assetKeys = [];
     foreach ($assets as $asset) {
         $assetKeys[] = $asset->id;
     }
     $model->imagesData = implode(';', $assetKeys);
     $model->tags = [];
     foreach ($tags as $tag) {
         $model->tags[] = $tag->id;
     }
     $relation = Relation::find()->where(['relationable_id' => $model->id, 'relationable_type' => Relation::RELATIONABLE_ALBUM])->one();
     $matchModel = new \common\models\MatchSearch();
     $matchesList = [];
     if (!isset($relation)) {
         $relation = new Relation();
         $relation->relationable_type = Relation::RELATIONABLE_ALBUM;
     }
     if (!isset($relation->match)) {
         $matches = $matchModel::find()->orderBy(['date' => SORT_DESC])->limit(10)->all();
         foreach ($matches as $match) {
             $matchDate = date('d.m.Y', strtotime($match->date));
             $matchesList[$match->id] = $match->name . ' (' . $matchDate . ')';
         }
     } else {
         $matchModel->championship_id = $relation->match->championship_id;
         $matchModel->league_id = $relation->match->league_id;
         $matchModel->season_id = $relation->match->season_id;
         $matchModel->command_home_id = $relation->match->command_home_id;
         $matchModel->command_guest_id = $relation->match->command_guest_id;
         $matchDate = date('d.m.Y', strtotime($relation->match->date));
         $matchesList[$relation->match->id] = $relation->match->name . ' (' . $matchDate . ')';
     }
     $model->title = html_entity_decode($model->title);
     $model->description = html_entity_decode($model->description);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         // Set slug
         $model->slug = $model->genSlug($model->title);
         // Save cover image
         $uploadedFile = UploadedFile::getInstance($model, 'coverImage');
         if (!empty($uploadedFile)) {
             // Save origionals
             $originalAsset = $model->getCoverImageAsset();
             if (!isset($originalAsset->id)) {
                 $originalAsset = new Asset();
             }
             $originalAsset->assetable_type = Asset::ASSETABLE_ALBUM_COVER;
             $originalAsset->assetable_id = $model->id;
             $originalAsset->uploadedFile = $uploadedFile;
             $originalAsset->saveAsset();
             // Save thumbnails
             $imageID = $originalAsset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_ALBUM_COVER);
             foreach ($thumbnails as $thumbnail) {
                 $asset = $model->getCoverImageAsset($thumbnail);
                 if (!isset($asset->id)) {
                     $asset = new Asset();
                 }
                 $asset->assetable_type = Asset::ASSETABLE_ALBUM_COVER;
                 $asset->assetable_id = $model->id;
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->saveAsset();
             }
         }
         // Remove selected images
         $currentAssetKeys = explode(';', $model->imagesData);
         if (count($currentAssetKeys) > 0) {
             foreach ($assets as $asset) {
                 if (!in_array($asset->id, $currentAssetKeys)) {
                     $imageID = $asset->parent_id;
                     foreach ($allAssets as $allAssetModel) {
                         if ($allAssetModel->parent_id == $imageID || $allAssetModel->id == $imageID) {
                             $allAssetModel->delete();
                         }
                     }
                 }
             }
         }
         // Remove not existing images
         $imageIDs = [];
         foreach ($allAssets as $asset) {
             $imageID = $asset->parent_id;
             if (!in_array($imageID, $imageIDs) && !file_exists($asset->getFilePath())) {
                 $imageIDs[] = $imageID;
                 foreach ($allAssets as $allAssetModel) {
                     if ($allAssetModel->parent_id == $imageID || $allAssetModel->id == $imageID) {
                         $allAssetModel->delete();
                     }
                 }
             }
         }
         // Save images
         $uploadedFiles = UploadedFile::getInstances($model, 'images');
         if ($uploadedFiles) {
             foreach ($uploadedFiles as $image) {
                 // Save origionals
                 $asset = new Asset();
                 $asset->assetable_type = Asset::ASSETABLE_ALBUM;
                 $asset->assetable_id = $model->id;
                 $asset->uploadedFile = $image;
                 $asset->saveAsset();
                 // Save thumbnails
                 $imageID = $asset->id;
                 $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_ALBUM);
                 foreach ($thumbnails as $thumbnail) {
                     $asset = new Asset();
                     $asset->parent_id = $imageID;
                     $asset->thumbnail = $thumbnail;
                     $asset->assetable_type = Asset::ASSETABLE_ALBUM;
                     $asset->assetable_id = $model->id;
                     $asset->uploadedFile = $image;
                     $asset->saveAsset();
                 }
             }
         }
         $existingTags = [];
         // Remove tags
         foreach ($tags as $tag) {
             if (!in_array($tag->id, $model->tags)) {
                 $model->removeTag($tag->id);
             } else {
                 $existingTags[] = $tag->id;
             }
         }
         // Adding new tags
         if (is_array($model->tags)) {
             foreach ($model->tags as $id) {
                 if (!in_array($id, $existingTags)) {
                     $model->addTag($id);
                 }
             }
         }
         $cached_tag_list = [];
         $newTags = $model->getTags();
         foreach ($newTags as $newTag) {
             $cached_tag_list[] = $newTag->name;
         }
         $model->cached_tag_list = implode(', ', $cached_tag_list);
         if (!isset($relation->relationable_id)) {
             $relation->relationable_id = $model->id;
             $relation->relationable_type = Relation::RELATIONABLE_ALBUM;
         }
         if ($relation->load(Yii::$app->request->post()) && $model->validate()) {
             if ($relation->parent_id != '' && is_array($relation->parent_id)) {
                 $relation->parent_id = $relation->parent_id[0];
             }
             if ($relation->parent_id && is_numeric($relation->parent_id)) {
                 $relation->save();
             } elseif (isset($relation->id)) {
                 $relation->delete();
             }
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'images' => $assets, 'coverImage' => $coverImage, 'tags' => $tags, 'relation' => $relation, 'matchModel' => $matchModel, 'matchesList' => $matchesList]);
     }
 }
Пример #5
0
 /**
  * Get match name
  * @return string
  */
 public function getMatchName()
 {
     $matchTable = Match::tableName();
     $relationTable = Relation::tableName();
     $match = Match::find()->innerJoin($relationTable, "{$matchTable}.id = {$relationTable}.parent_id")->where(["{$relationTable}.relationable_type" => Relation::RELATIONABLE_ALBUM, "{$relationTable}.relationable_id" => $this->id])->one();
     if (!isset($match)) {
         return 'Матч не найден';
     } else {
         $date = date('d.m.Y', strtotime($match->date));
         return $match->name . ' (' . $date . ')';
     }
     return '';
 }
Пример #6
0
 /**
  * Url: /match/{$id}/videos
  * @param $id Match id
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionMatchVideos($id)
 {
     $match = Match::findOne($id);
     if (!isset($match)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $title = "Видео матча " . $match->name;
     $videoPostTable = VideoPost::tableName();
     $relationTable = Relation::tableName();
     $query = VideoPost::find()->innerJoin($relationTable, "{$videoPostTable}.id = {$relationTable}.relationable_id")->where(['is_public' => 1, "{$relationTable}.relationable_type" => Relation::RELATIONABLE_VIDEO, "{$relationTable}.parent_id" => $match->id])->orderBy(['created_at' => SORT_DESC]);
     $videosDataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $emptyText = 'Видеозаписей к матчу не найдено';
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $title, 'columnFirst' => ['menu' => ['view' => '@frontend/views/translation/menu', 'data' => compact('match')], 'content' => ['view' => '@frontend/views/site/videos', 'data' => compact('videosDataProvider', 'emptyText')]], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]);
 }
Пример #7
0
 /**
  * @inheritdoc
  */
 public function afterDelete()
 {
     $this->updateCacheBlocks();
     Tagging::deleteAll(['taggable_type' => Tagging::TAGGABLE_POST, 'taggable_id' => $this->id]);
     Relation::deleteAll(['relationable_type' => Relation::RELATIONABLE_POST, 'relationable_id' => $this->id]);
     Comment::deleteAll(['commentable_type' => Comment::COMMENTABLE_POST, 'commentable_id' => $this->id]);
     CommentCount::deleteAll(['commentable_type' => CommentCount::COMMENTABLE_POST, 'commentable_id' => $this->id]);
     SelectedBlog::deleteAll(['post_id' => $this->id]);
     $assets = Asset::find()->where(['assetable_type' => Asset::ASSETABLE_POST, 'assetable_id' => $this->id])->all();
     foreach ($assets as $asset) {
         $asset->delete();
     }
 }