Пример #1
0
 /**
  * Update an existing User model. If update is successful, the browser
  * will be redirected to the 'view' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     // set up user and profile
     $user = $this->findModel($id);
     $user->setScenario("admin");
     $profile = $user->profile;
     $avatar = $user->getAsset(Asset::THUMBNAIL_CONTENT);
     // load post data and validate
     $post = Yii::$app->request->post();
     if ($user->load($post) && $user->validate() && $profile->load($post) && $profile->validate()) {
         $uploadedFile = UploadedFile::getInstance($user, 'avatar');
         // If image was uploaded
         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();
             }
         }
         $user->save(false);
         $profile->setUser($user->id)->save(false);
         return $this->redirect(['view', 'id' => $user->id]);
     }
     // render
     return $this->render('update', ['user' => $user, 'avatar' => $avatar, 'profile' => $profile]);
 }
 /**
  * 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 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]);
     }
 }
 /**
  * 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()]]);
 }
 /**
  * Updates an existing Player 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(Asset::THUMBNAIL_CONTENT);
     $achievementModel = new AchievementSearch();
     $params = ['AchievementSearch' => ['player_id' => $model->id]];
     $achievementDataProvider = $achievementModel->search($params);
     $model->birthday = date('d.m.Y', strtotime($model->birthday));
     $searchModel = new CareerSearch();
     // careerDataProvider
     $params = ['CareerSearch' => ['player_id' => $model->id]];
     $careerDataProvider = $searchModel->search($params);
     $careerDataProvider->setSort(['defaultOrder' => ['season_id' => SORT_DESC]]);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $uploadedFile = UploadedFile::getInstance($model, 'avatar');
         // If image was uploaded
         if (!empty($uploadedFile)) {
             // Save origionals
             $originalAsset = $model->getAsset();
             if (!isset($originalAsset->id)) {
                 $originalAsset = new Asset();
             }
             $originalAsset->assetable_type = Asset::ASSETABLE_PLAYER;
             $originalAsset->assetable_id = $model->id;
             $originalAsset->uploadedFile = $uploadedFile;
             $originalAsset->saveAsset();
             // Save thumbnails
             $imageID = $originalAsset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_PLAYER);
             foreach ($thumbnails as $thumbnail) {
                 $asset = $model->getAsset($thumbnail);
                 if (!isset($asset->id)) {
                     $asset = new Asset();
                 }
                 $asset->assetable_type = Asset::ASSETABLE_PLAYER;
                 $asset->assetable_id = $model->id;
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->cropData = $model->cropData;
                 $asset->saveCroppedAsset();
             }
         }
         $model->slug = $model->genSlug();
         $model->birthday = date('Y-m-d', strtotime($model->birthday));
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'achievementModel' => $achievementModel, 'achievementDataProvider' => $achievementDataProvider, 'image' => $image, 'careerDataProvider' => $careerDataProvider]);
 }
Пример #7
0
 /**
  * Url: /post/edit/{$id}
  * @param $id int Post id
  * @return mixed
  * @throws ForbiddenHttpException
  * @throws NotFoundHttpException
  */
 public function actionPostEdit($id)
 {
     $model = Post::findOne($id);
     if (!isset($model)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     if ($model->content_category_id != Post::CATEGORY_BLOG || empty(Yii::$app->user) || $model->user_id != Yii::$app->user->id) {
         throw new ForbiddenHttpException("Вы не можете выполнить это действие.");
     }
     $image = $model->getAsset();
     $tags = $model->getTags();
     $assets = $model->getAssets();
     $model->tags = [];
     foreach ($tags as $tag) {
         $model->tags[] = $tag->id;
     }
     $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_POST;
             $asset->assetable_id = $model->id;
             $asset->uploadedFile = $uploadedFile;
             $asset->saveAsset();
             // Save thumbnails
             $imageID = $asset->id;
             $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_POST);
             foreach ($thumbnails as $thumbnail) {
                 $asset = new Asset();
                 $asset->parent_id = $imageID;
                 $asset->thumbnail = $thumbnail;
                 $asset->assetable_type = Asset::ASSETABLE_POST;
                 $asset->assetable_id = $model->id;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->saveAsset();
             }
         }
         $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);
         $model->save();
         return $this->redirect($model->getUrl());
     }
     $title = 'Изменить запись в блоге';
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $title, 'columnFirst' => ['blog_form' => ['view' => '@frontend/views/forms/blog_form', 'data' => compact('model', 'tags', 'image', 'title')]], 'columnSecond' => ['blog' => SiteBlock::getBlogPosts(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]]);
 }