/**
  * @return Asset
  */
 public function getAsset()
 {
     $asset = Asset::getAssets($this->id, Asset::ASSETABLE_MATCH_EVENT, NULL, true);
     if ($asset->assetable_type == null) {
         $asset->assetable_type = Asset::ASSETABLE_MATCH_EVENT;
     }
     return $asset;
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Asset::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['Id' => $this->Id, 'createdBy' => $this->createdBy, 'updatedBy' => $this->updatedBy, 'createdOn' => $this->createdOn, 'modifiedOn' => $this->modifiedOn, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'filename', $this->filename])->andFilterWhere(['like', 'path', $this->path])->andFilterWhere(['like', 'uri', $this->uri])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'mimetype', $this->mimetype])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'embedcode', $this->embedcode])->andFilterWhere(['like', 'mediahash', $this->mediahash])->andFilterWhere(['like', 'metainfo', $this->metainfo])->andFilterWhere(['like', 'ip', $this->ip]);
     return $dataProvider;
 }
 protected function importimagefromstr($media, $path, $flag)
 {
     $mediaIds = [];
     yii::info($media, __METHOD__);
     $hash = md5($media);
     if (($armodel = Asset::findOne(['mediahash' => $hash])) !== null) {
         return [$armodel->Id];
     }
     $media_doc = ['filename' => $media, 'path' => '@media/' . $path . '/' . $media, 'uri' => $path . '/' . $media, 'description' => '', 'mimetype' => '', 'source' => '', 'embedcode' => '', 'mediahash' => $hash, 'metainfo' => '', 'createdBy' => 40, 'updatedBy' => 40, 'status' => 1];
     $assetmodel = new Asset();
     $assetmodel->load($media_doc, '');
     $assetmodel->save(false);
     $mediaIds[] = $assetmodel->Id;
     try {
         $tag = Asset::loadTagmodel($flag, true);
         Asset::saveAssetTag($assetmodel, $tag);
     } catch (\yii\base\ErrorException $error) {
         Yii::info(print_r($error, true), __METHOD__);
     }
     return $mediaIds;
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAssets()
 {
     return $this->hasMany(Asset::className(), ['Id' => 'assetId'])->via('tagassetmaps');
 }
 /**
  * Url: /album/{$album_id}-{$slug}/{$photo_id}
  * @param int $album_id Album id
  * @param string $slug Album slug
  * @param $photo_id
  * @return mixed Content
  * @throws NotFoundHttpException
  */
 public function actionPhoto($album_id, $slug, $photo_id)
 {
     $album = Album::find()->where(['id' => $album_id, 'is_public' => 1])->one();
     if (!isset($album)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     $photo = Asset::find()->where(['id' => $photo_id, 'thumbnail' => Asset::THUMBNAIL_CONTENT])->one();
     if (!isset($photo)) {
         $photo = Asset::find()->where(['id' => $photo_id])->one();
     }
     if (!isset($photo)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Фотоальбом: ' . $album->title, 'columnFirst' => ['content' => ['view' => '@frontend/views/site/photo_single', 'data' => compact('album', 'photo')], 'comments' => Comment::getCommentsBlock($photo->id, Comment::COMMENTABLE_PHOTO)], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]);
 }
 /**
  * Deletes an existing Coach model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $assets = Asset::getAssets($model->id, Asset::ASSETABLE_USER, NULL);
     foreach ($assets as $asset) {
         $asset->delete();
     }
     $model->delete();
     return $this->redirect(['index']);
 }
Example #7
0
 /**
  * Get all assets file for assetable entity
  *
  * @param int $assetableId
  * @param string $assetableType
  * @param string $thumbnail
  * @param boolean $single
  *
  * @return array[Asset] or Asset if $single == true
  */
 public static function getAssets($assetableId, $assetableType, $thumbnail = null, $single = false)
 {
     $query = Asset::find()->where(['assetable_id' => $assetableId, 'assetable_type' => $assetableType]);
     if (isset($thumbnail)) {
         if ($thumbnail === false) {
             $query->andWhere(['thumbnail' => null]);
         } else {
             $query->andWhere(['thumbnail' => $thumbnail]);
         }
     }
     if (!$single) {
         return $query->all();
     }
     $asset = $query->one();
     if (isset($asset)) {
         return $asset;
     } else {
         $asset = new Asset();
         $asset->assetable_type = $assetableType;
         return $asset;
     }
 }
Example #8
0
 /**
  * Save Asset with Tag
  * 
  * @param Integer $assetId the Asset Id.
  * @return ActiveRecord Asset Model
  */
 public function loadAsset($assetId)
 {
     if (($model = Asset::findOne($assetId)) !== null) {
         return $model;
     } else {
         //throw new NotFoundHttpException('The requested page does not exist.');
         yii::warning('asset id= ' . $assetId . ' not found');
     }
 }
Example #9
0
 /**
  * Get block with video reviews
  * @return array Data
  */
 public static function getVideoNews()
 {
     $postTable = Post::tableName();
     $assetTable = Asset::tableName();
     // Video review
     $videoReviewNews = VideoPost::find()->where(['is_public' => 1])->orderBy(['created_at' => SORT_DESC])->limit(3)->all();
     if (count($videoReviewNews) == 0) {
         return false;
     }
     $block = ['view' => '@frontend/views/blocks/review_news_block', 'data' => compact('videoReviewNews')];
     return $block;
 }
Example #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAssetId()
 {
     return $this->hasOne(Asset::className(), ['Id' => 'assetId']);
 }
 /**
  * Account
  */
 public function actionAccount()
 {
     /** @var \common\modules\user\models\User $user */
     /** @var \common\modules\user\models\UserKey $userKey */
     // set up user and load post data
     $user = Yii::$app->user->identity;
     $user->setScenario("account");
     $loadedUser = $user->load(Yii::$app->request->post());
     // set up profile and load post data
     $profile = Yii::$app->user->identity->profile;
     $loadedProfile = $profile->load(Yii::$app->request->post());
     // validate for ajax request
     if ($loadedUser && Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($user);
     }
     // validate for normal request
     if ($loadedUser && $user->validate() && $loadedProfile && $profile->validate()) {
         // generate userKey and send email if user changed his email
         if (Yii::$app->getModule("user")->emailChangeConfirmation && $user->checkAndPrepEmailChange()) {
             $userKey = Yii::$app->getModule("user")->model("UserKey");
             $userKey = $userKey::generate($user->id, $userKey::TYPE_EMAIL_CHANGE);
             if (!($numSent = $user->sendEmailConfirmation($userKey))) {
                 // handle email error
                 //Yii::$app->session->setFlash("Email-error", "Failed to send email");
             }
         }
         // save avatar
         $uploadedFile = UploadedFile::getInstance($user, 'avatar');
         if (!empty($uploadedFile)) {
             // Save origionals
             $originalAsset = $user->getAsset();
             if (!isset($originalAsset->id)) {
                 $originalAsset = new Asset();
             }
             $originalAsset->assetable_type = Asset::ASSETABLE_USER;
             $originalAsset->assetable_id = $user->id;
             $originalAsset->uploadedFile = $uploadedFile;
             $originalAsset->saveAsset();
             // Save thumbnails
             $imageID = $originalAsset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_USER);
             foreach ($thumbnails as $thumbnail) {
                 $asset = $user->getAsset($thumbnail);
                 if (!isset($asset->id)) {
                     $asset = new Asset();
                 }
                 $asset->assetable_type = Asset::ASSETABLE_USER;
                 $asset->assetable_id = $user->id;
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->cropData = $user->cropData;
                 $asset->saveCroppedAsset();
             }
         }
         // save, set flash, and refresh page
         $user->save(false);
         $profile->save(false);
         Yii::$app->session->setFlash("success-account", Yii::t("user", "Account updated"));
         if (Yii::getAlias('@app') == Yii::getAlias('@frontend')) {
             return Yii::$app->getResponse()->redirect(\yii\helpers\Url::to('/user/profile'));
         }
     }
     // render
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => Yii::t('user', 'Вход'), 'columnFirst' => ['profile_edit' => ['view' => '@frontend/views/profile/profile_edit', 'data' => compact('user', 'profile')]], 'columnSecond' => ['blogs' => SiteBlock::getBlogPosts()]]);
 }
Example #12
0
 /**
  * 
  * @param integer $id media asset Id
  * @param string $table asset Table
  * @return \common\models\Asset
  */
 public static function loadAssetmodel($id, $table)
 {
     if (($model = Asset::findOne(['remoteId' => $id, 'table' => $table])) !== null) {
     } else {
         $model = new Asset();
     }
     return $model;
 }
 /**
  * Save Asset with Tag
  * 
  * @param Integer $assetId the Asset Id.
  * @return ActiveRecord Asset Model
  */
 public function loadAsset($assetId)
 {
     if (($model = Asset::findOne($assetId)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Finds the Asset model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Asset the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Asset::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #15
0
 /**
  * Get single video asset
  * @return Asset
  */
 public function getVideoAsset()
 {
     return Asset::getAssets($this->id, Asset::ASSETABLE_VIDEOFILE, NULL, true);
 }
Example #16
0
    /**
     * Output tree of comments
     * @param array $comments Array of Comment
     * @param int $parent_id 
     * @param array $options 
     */
    public static function outCommentsTree($comments, $parent_id, $options)
    {
        if (!isset($options) || !is_object($options)) {
            $showReplies = isset($options['showReplies']) ? $options['showReplies'] : true;
            $showReplyButton = isset($options['showReplyButton']) ? $options['showReplyButton'] : true;
            $postID = isset($options['postID']) ? $options['postID'] : false;
            $options = (object) compact('showReplies', 'showReplyButton', 'postID');
        }
        if (isset($comments[$parent_id])) {
            foreach ($comments[$parent_id] as $comment) {
                if (is_null($comment->user)) {
                    $username = '******';
                    $avatar = new Asset();
                    $avatar->assetable_type = Asset::ASSETABLE_USER;
                    $imageUrl = $avatar->getDefaultFileUrl();
                    $userUrl = false;
                } else {
                    $username = $comment->user->getDisplayName();
                    $avatar = $comment->user->getAsset();
                    $imageUrl = $avatar->getFileUrl();
                    $userUrl = $comment->user->getUrl();
                }
                $commentDate = Yii::$app->formatter->asDate(strtotime($comment->created_at), 'd MMMM Y HH:mm');
                $repliesCommentsCount = isset($comments[$comment->id]) ? count($comments[$comment->id]) : 0;
                $classRepliesCount = $repliesCommentsCount == 0 ? 'no-replies' : '';
                $textRepliesCount = $repliesCommentsCount == 0 ? '' : $repliesCommentsCount;
                $isReply = $parent_id == 0 ? false : true;
                $own = isset(Yii::$app->user->id) && Yii::$app->user->id == $comment->user_id ? 'yes' : 'no';
                $rating = $comment->getRating();
                $ratingUpClass = '';
                $ratingDownClass = '';
                if (!Yii::$app->user->isGuest && Yii::$app->user->id != $comment->user_id) {
                    $userRating = $comment->getUserVote();
                    if ($userRating == 1) {
                        $ratingUpClass = 'voted';
                    } elseif ($userRating == -1) {
                        $ratingDownClass = 'voted';
                    }
                } else {
                    $ratingUpClass = 'disable';
                    $ratingDownClass = 'disable';
                }
                $commentLevelClass = $parent_id == 0 ? 'lvl-one' : '';
                if ($parent_id == 0 && $options->postID && $comment->getCommentableType() == Comment::COMMENTABLE_POST) {
                    $post = Post::findOne($comment->commentable_id);
                    if (isset($post->id) && $post->id !== $options->postID) {
                        $options->postID = $post->id;
                        ?>
                        <div class="comment-theme">
                            <div class="theme-label">Комментарии по теме:</div>
                            <div class="theme-link">
                                <a href="<?php 
                        echo $post->getUrl();
                        ?>
" data-pjax="0"><?php 
                        echo $post->title;
                        ?>
</a>
                            </div>
                        </div>
                        <?php 
                    }
                }
                $adminLink = '';
                if (Yii::$app->user->can('admin')) {
                    $adminLink = '<a class="admin-view-link" target="_blank" href="/admin/comment/' . $comment->id . '" data-pjax="0"></a>';
                }
                ?>
                <div id="comment-<?php 
                echo $comment->id;
                ?>
" class="comment <?php 
                echo $commentLevelClass;
                ?>
" 
                    data-own="<?php 
                echo $own;
                ?>
"
                    data-comment-id="<?php 
                echo $comment->id;
                ?>
"
                    data-commentable-type="<?php 
                echo $comment->getCommentableType();
                ?>
"
                    data-commentable-id="<?php 
                echo $comment->commentable_id;
                ?>
" >
                    <div class="comment-user">
                        <div class="user-photo">
                            <?php 
                if ($userUrl) {
                    ?>
                                <a href="<?php 
                    echo $userUrl;
                    ?>
" data-pjax="0">
                            <?php 
                }
                ?>
                                <img src="<?php 
                echo $imageUrl;
                ?>
">
                            <?php 
                if ($userUrl) {
                    ?>
                                </a>
                            <?php 
                }
                ?>

                        </div>
                        <div class="user-info">
                            <div class="user-name">
                                <?php 
                if ($userUrl) {
                    ?>
                                    <a href="<?php 
                    echo $userUrl;
                    ?>
" data-pjax="0">
                                <?php 
                }
                ?>
                                    <?php 
                echo $username;
                ?>
                                <?php 
                if ($userUrl) {
                    ?>
                                    </a>
                                <?php 
                }
                ?>
                            </div>
                            <div class="post-time"><?php 
                echo $commentDate;
                ?>
</div>
                        </div>
                    </div>
                    <div class="comment-links">
                        <div class="rating-counter">
                            <a href="javascript:void(0)" class="rating-up <?php 
                echo $ratingUpClass;
                ?>
" data-id="<?php 
                echo $comment->id;
                ?>
" data-type="comment"></a>
                            <div class="rating-count <?php 
                echo $rating >= 0 ? 'blue' : 'red';
                ?>
"><?php 
                echo $rating;
                ?>
</div>
                            <a href="javascript:void(0)" class="rating-down <?php 
                echo $ratingDownClass;
                ?>
" data-id="<?php 
                echo $comment->id;
                ?>
" data-type="comment"></a>
                        </div>
                        <?php 
                if (!Yii::$app->user->isGuest) {
                    ?>
                            <a href="<?php 
                    echo Url::to('/complain/' . $comment->id);
                    ?>
" class="button-complain" title="Пожаловаться" data-pjax="0"></a>
                        <?php 
                }
                ?>
                        <?php 
                if (!Yii::$app->user->isGuest && $options->showReplyButton) {
                    ?>
                            <a href="javascript:void(0)" class="button-reply" title="Ответить"></a>
                        <?php 
                }
                ?>
                        <?php 
                echo $adminLink;
                ?>
                    </div>
                    <div class="comment-body">
                        <?php 
                echo $comment->getContent();
                ?>
                    </div>
                    <?php 
                if ($repliesCommentsCount > 0) {
                    ?>
                    <div class="comment-replies">
                        <a class="replies-toggle-btn toggle-button toggle-<?php 
                    echo $options->showReplies ? 'hide' : 'show';
                    ?>
" data-target="comment-replies-content-<?php 
                    echo $comment->id;
                    ?>
" href="javascript:void(0)">
                            <div class="toggle-text">
                                <span><?php 
                    echo $options->showReplies ? 'Скрыть' : 'Показать';
                    ?>
</span> ответы
                            </div>
                            <div class="toggle-icon"></div>
                        </a>
                        <div id="comment-replies-content-<?php 
                    echo $comment->id;
                    ?>
" class="toggle-content <?php 
                    echo $options->showReplies ? 'visible' : '';
                    ?>
">
                        <?php 
                    self::outCommentsTree($comments, $comment->id, $options);
                    ?>
                        </div>
                    </div>
                    <?php 
                }
                ?>
                </div>
                <?php 
            }
        }
    }
 /**
  * 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]);
     }
 }
Example #18
0
 /**
  * Get amount of photos in album
  * @return int
  */
 public function getPhotosCount()
 {
     $count = Asset::find()->where(['assetable_id' => $this->id, 'assetable_type' => Asset::ASSETABLE_ALBUM, 'parent_id' => null])->count();
     return $count;
 }
 /**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userkeys first to handle foreign key constraint
     $user = $this->findModel($id);
     // Sidash
     if ($user->id == 1) {
         return $this->redirect(['index']);
     }
     $profile = $user->profile;
     UserKey::deleteAll(['user_id' => $user->id]);
     UserAuth::deleteAll(['user_id' => $user->id]);
     $profile->delete();
     $user->delete();
     $assets = Asset::getAssets($user->id, Asset::ASSETABLE_USER, null);
     foreach ($assets as $asset) {
         $asset->delete();
     }
     return $this->redirect(['index']);
 }
Example #20
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAssets()
 {
     return $this->hasMany(Asset::className(), ['user_id' => 'id']);
 }
Example #21
0
 /**
  * @return Asset
  */
 public function getAsset($thumbnail = Asset::THUMBNAIL_CONTENT)
 {
     return Asset::getAssets($this->id, Asset::ASSETABLE_TEAM, $thumbnail, true);
 }
Example #22
0
 /**
  * @return Asset
  */
 public function getAsset($thumbnail = Asset::THUMBNAIL_SMALL)
 {
     return Asset::getAssets($this->id, Asset::ASSETABLE_COUNTRY, $thumbnail, true);
 }
 /**
  * Updates an existing Country 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);
     $flag = $model->getAsset();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $uploadedFile = UploadedFile::getInstance($model, 'flag');
         // If image was uploaded
         if (!empty($uploadedFile)) {
             // Save origionals
             $originalAsset = $model->getAsset();
             if (!isset($originalAsset->id)) {
                 $originalAsset = new Asset();
             }
             $originalAsset->assetable_type = Asset::ASSETABLE_COUNTRY;
             $originalAsset->assetable_id = $model->id;
             $originalAsset->uploadedFile = $uploadedFile;
             $originalAsset->saveAsset();
             // Save thumbnails
             $imageID = $originalAsset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_COUNTRY);
             foreach ($thumbnails as $thumbnail) {
                 $asset = $model->getAsset($thumbnail);
                 if (!isset($asset->id)) {
                     $asset = new Asset();
                 }
                 $asset->assetable_type = Asset::ASSETABLE_COUNTRY;
                 $asset->assetable_id = $model->id;
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->saveAsset();
             }
         }
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'flag' => $flag]);
 }
 /**
  * Updates an existing MatchEventType 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);
     $icon = $model->getAsset();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->icon = UploadedFile::getInstance($model, 'icon');
         // If image was uploaded
         if (!empty($model->icon)) {
             // If asset model did't exist for current model
             if (!isset($icon->assetable_id)) {
                 $icon = new Asset();
                 $icon->assetable_type = Asset::ASSETABLE_MATCH_EVENT;
                 $icon->assetable_id = $model->id;
             }
             $icon->uploadedFile = $model->icon;
             $icon->saveAsset();
         }
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'icon' => $icon]);
 }
Example #25
0
 /**
  * @return Asset
  */
 public function getAsset($thumbnail = false)
 {
     return Asset::getAssets($this->id, Asset::ASSETABLE_COACH, $thumbnail, true);
 }
 /**
  * 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]);
     }
 }
Example #27
0
 /**
  * Get guest team logo asset
  *
  * @return Asset
  */
 public function getAssetGuest()
 {
     return Asset::getAssets($this->command_guest_id, Asset::ASSETABLE_TEAM, NULL, true);
 }
Example #28
0
 /**
  * Get single asset
  *
  * @param string $thumbnail
  *
  * @return Asset
  */
 public function getAsset($thumbnail = NULL)
 {
     return Asset::getAssets($this->id, Asset::ASSETABLE_POST, $thumbnail, true);
 }