Ejemplo n.º 1
0
 /**
  * Url: /video/{$id}-{$slug}
  * @param int $id Album id
  * @param string $slug Album slug
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionVideoPost($id, $slug)
 {
     $videoPost = VideoPost::find()->where(['id' => $id, 'is_public' => 1])->one();
     if (!isset($videoPost)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     $image = $videoPost->getAsset();
     $video = $videoPost->getVideoAsset();
     $options = ['templateType' => 'col2', 'title' => 'Dynamomania.com | Видео: ' . $videoPost->title, 'columnFirst' => ['content' => ['view' => '@frontend/views/site/video_post', 'data' => compact('videoPost', 'image', 'video')]], 'columnSecond' => ['short_news' => SiteBlock::getShortNews()]];
     $banner = SiteBlock::getBanner(Banner::REGION_UNDER_NEWS);
     $count = 0;
     while ($banner) {
         $count++;
         $options['columnFirst']['banner-' . $count] = $banner;
         $options['columnFirst']['banner-' . $count]['weight'] = 2;
         $banner = SiteBlock::getBanner(Banner::REGION_UNDER_NEWS);
     }
     $options['columnFirst']['comments'] = Comment::getCommentsBlock($videoPost->id, Comment::COMMENTABLE_VIDEO);
     $options['columnFirst']['comments']['weight'] = 5;
     usort($options['columnFirst'], 'self::cmp');
     return $this->render('@frontend/views/site/index', $options);
 }
 /**
  * Reset password
  */
 public function actionReset($key)
 {
     /** @var \common\modules\user\models\User    $user */
     /** @var \common\modules\user\models\UserKey $userKey */
     // check for valid userKey
     $userKey = Yii::$app->getModule("user")->model("UserKey");
     $userKey = $userKey::findActiveByKey($key, $userKey::TYPE_PASSWORD_RESET);
     if (!$userKey) {
         return $this->render('reset', ["invalidKey" => true]);
     }
     // get user and set "reset" scenario
     $success = false;
     $user = Yii::$app->getModule("user")->model("User");
     $user = $user::findOne($userKey->user_id);
     $user->setScenario("reset");
     // load post data and reset user password
     if ($user->load(Yii::$app->request->post()) && $user->save()) {
         // consume userKey and set success = true
         $userKey->consume();
         $success = true;
     }
     // render
     // return $this->render('reset', compact("user", "success"));
     return $this->render('@frontend/views/site/index', ['templateType' => 'col3', 'title' => Yii::t('user', 'Вход'), 'columnFirst' => ['top3News' => SiteBlock::getTop3News(), 'top6News' => SiteBlock::getTop6News(), 'subscribing' => SiteBlock::getSubscribingForm(), 'blog_column' => SiteBlock::getBlogPosts()], 'columnSecond' => ['forgot_block' => ['view' => 'reset', 'data' => compact('user', 'success')], 'short_news' => SiteBlock::getShortNews()], 'columnThird' => ['reviewNews' => SiteBlock::getPhotoVideoNews(), 'questionBlock' => SiteBlock::getQuestionBlock(), 'tournament' => SiteBlock::getTournamentTable()]]);
 }
Ejemplo n.º 3
0
 /**
  * After save and before delete update cache of blocks
  */
 public function updateCacheBlocks($changedAttributes)
 {
     $newsPosts50 = Post::find()->where(['is_public' => 1, 'content_category_id' => Post::CATEGORY_NEWS])->orderBy(['created_at' => SORT_DESC])->limit(50)->all();
     $newsPosts20 = array_slice($newsPosts50, 0, 20);
     $cacheBlocksData = CacheBlock::find()->all();
     $cacheBlocks = [];
     foreach ($cacheBlocksData as $block) {
         $cacheBlocks[$block->machine_name] = $block;
     }
     $cacheStatus = false;
     if (isset($changedAttributes['content_category_id']) && $changedAttributes['content_category_id'] == self::CATEGORY_NEWS && $this->content_category_id != self::CATEGORY_NEWS || $this->content_category_id == self::CATEGORY_NEWS) {
         $machineName = 'shortNews50';
         $enableBanners = false;
         if (!isset($cacheBlocks[$machineName])) {
             $cacheBlock = new CacheBlock();
             $cacheBlock->machine_name = $machineName;
         } else {
             $cacheBlock = $cacheBlocks[$machineName];
         }
         $cacheBlock->content = SiteBlock::getShortNews(50, $enableBanners, $cacheStatus, $newsPosts50);
         $cacheBlock->save();
         $machineName = 'shortNews50banners';
         $enableBanners = true;
         SiteBlock::$postedBannerIds = [];
         if (!isset($cacheBlocks[$machineName])) {
             $cacheBlock = new CacheBlock();
             $cacheBlock->machine_name = $machineName;
         } else {
             $cacheBlock = $cacheBlocks[$machineName];
         }
         $cacheBlock->content = SiteBlock::getShortNews(50, $enableBanners, $cacheStatus, $newsPosts50);
         $cacheBlock->save();
     }
     if (isset($changedAttributes['is_index']) && $this->is_index != $changedAttributes['is_index'] || isset($changedAttributes['is_top']) && $this->is_top != $changedAttributes['is_top'] || $this->is_top || $this->is_index) {
         $machineName = 'top3News';
         if (!isset($cacheBlocks[$machineName])) {
             $cacheBlock = new CacheBlock();
             $cacheBlock->machine_name = $machineName;
         } else {
             $cacheBlock = $cacheBlocks[$machineName];
         }
         $cacheBlock->content = SiteBlock::getTop3News($cacheStatus);
         $cacheBlock->save();
         $machineName = 'top6News';
         if (!isset($cacheBlocks[$machineName])) {
             $cacheBlock = new CacheBlock();
             $cacheBlock->machine_name = $machineName;
         } else {
             $cacheBlock = $cacheBlocks[$machineName];
         }
         $cacheBlock->content = SiteBlock::getTop6News($cacheStatus);
         $cacheBlock->save();
     }
     if ($this->content_category_id == self::CATEGORY_BLOG) {
         $machineName = 'lastBlogPosts';
         if (!isset($cacheBlocks[$machineName])) {
             $cacheBlock = new CacheBlock();
             $cacheBlock->machine_name = $machineName;
         } else {
             $cacheBlock = $cacheBlocks[$machineName];
         }
         $cacheBlock->content = SiteBlock::getBlogPosts($cacheStatus);
         $cacheBlock->save();
         $machineName = 'blogPostsByRating';
         if (!isset($cacheBlocks[$machineName])) {
             $cacheBlock = new CacheBlock();
             $cacheBlock->machine_name = $machineName;
         } else {
             $cacheBlock = $cacheBlocks[$machineName];
         }
         $cacheBlock->content = SiteBlock::getBlogPostsByRating($cacheStatus);
         $cacheBlock->save();
     }
 }