Пример #1
0
 /**
  * Выставление оценки для статьи
  *
  * @return string
  * @throws \Exception
  */
 public function actionRating()
 {
     $message = '';
     if ((Yii::$app->request->get('score') == 1 || Yii::$app->request->get('score') == -1) && Yii::$app->request->get('post_id')) {
         $postId = Yii::$app->request->get('post_id');
         $score = Yii::$app->request->get('score');
         if (!Yii::$app->user->isGuest) {
             $rating = new PostsRating();
             $rating->post_id = $postId;
             $rating->user_id = Yii::$app->user->identity->getId();
             $rating->score = $score;
             try {
                 if ($rating->save()) {
                     $message = 'Спасибо! Ваш голос засчитан';
                 } else {
                     $err = $rating->errors;
                     $message = current($err)[0];
                 }
             } catch (IntegrityException $e) {
                 if (strpos($e->errorInfo[2], 'foreign key')) {
                     $message = 'Ошибка. Неверный ID статьи';
                 }
             }
         } else {
             $message = 'Голосовать могут только зарегистрированные пользователи';
         }
     } else {
         return 'Ошибка';
     }
     return RatingWidget::widget(['post_id' => $postId, 'message' => $message]);
 }
Пример #2
0
                <div class="clear"></div>
            </div>
            <div align="justify" style="color:#000000; font-size:14px; line-height: 1.5;" id="art_full"><?php 
echo $post->full;
?>
</div>
            <div class="related_posts">
                <strong>Другие публикации по теме:</strong><br/><?php 
echo SimilarPostsWidget::widget(['posts' => $post->similarPosts, 'list' => true, 'listType' => 'ol']);
?>
            </div>
        </div>
        <div class="clear"></div>
        <div id="content-item-rating">
            <div class="content-item-rating-1"><?php 
echo RatingWidget::widget(['post_id' => $post->id]);
?>
</div>
            <div class="content-item-favorite"><?php 
echo FavoriteWidget::widget(['post_id' => $post->id]);
?>
</div>
        </div>
        <div class="clear"></div>
        <div id="content-item-footer">
            <div style="color:#333; font-size:14px"><strong>Статья добавлена:</strong> <?php 
echo $post->date;
?>
 | <strong>Комментарии</strong> (<a href="#all-comments"><?php 
echo count($post->comments);
?>