예제 #1
0
 public static function setCommentLike($id, $val)
 {
     $val = $val >= 0 ? 1 : -1;
     $rate = self::model()->findByAttributes(array('comment_id' => $id, 'user_id' => Yii::app()->user->id));
     $comment = BooksComments::model()->findByPk($id);
     if (empty($rate)) {
         $rate = new CommentLike();
         $rate->comment_id = $id;
         $rate->user_id = Yii::app()->user->id;
     } else {
         if ($rate->val == $val) {
             $rate->delete();
             if (!empty($comment)) {
                 $comment->updateRate();
             }
             return 0;
         }
     }
     $rate->val = $val;
     $rate->save();
     if (!empty($comment)) {
         $comment->updateRate();
     }
     return $val;
 }
예제 #2
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete()
 {
     if (isset($_POST['trash'])) {
         $model = $this->loadModel($_POST['id']);
         if ($_POST['trash'] == 1) {
             $model->status = 2;
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 if ($model->save(true, array('status'))) {
                     Comment::model()->updateAllChildren($model->status, $model->id);
                 }
                 $transaction->commit();
                 Yii::app()->user->setFlash('success', Yii::t('comment', 'Comment moved to trash.'));
             } catch (Exception $ex) {
                 $transaction->rollback();
                 Yii::app()->user->setFlash('error', Yii::t('comment', 'Comment cannot move to trash. Please try it later.'));
             }
             $this->redirect(array('/' . backend . '/comment/admin'));
         } else {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 CommentLike::model()->deleteAllLike($model->id);
                 Comment::model()->deleteAllChildren($model->id);
                 if ($model->delete()) {
                     $transaction->commit();
                     Yii::app()->user->setFlash('success', Yii::t('comment', 'Comment was deleted from system.'));
                 }
             } catch (Exception $e) {
                 $transaction->rollback();
                 Yii::app()->user->setFlash('error', Yii::t('comment', 'Comment cannot delete. Please try it later.'));
             }
             $this->redirect(array('/' . backend . '/comment/trash'));
         }
     }
 }
예제 #3
0
 public function wasLiked()
 {
     $model = CommentLike::model()->findByAttributes(array('comment_id' => $this->id, 'user_id' => Yii::app()->user->id));
     if (empty($model)) {
         return 0;
     }
     return $model->val;
 }
 public function actionSetCommentLike($comment_id, $val)
 {
     /*
      * @var BooksComments $comment
      * */
     $result = array();
     $comment = BooksComments::model()->findByPk($comment_id);
     $result['status'] = CommentLike::setCommentLike($comment_id, $val);
     $result['like'] = $comment->getLike();
     $result['dislike'] = $comment->getLike('-');
     echo json_encode($result);
 }
예제 #5
0
 /**
  * Like for comment
  * @throws CHttpException
  */
 public function actionLike()
 {
     $id = @$_REQUEST['id'];
     $commentableType = @$_REQUEST['commentableType'];
     $commentable = Yii::createComponent($commentableType);
     /* @var $behavior CommentableBehavior */
     $behavior = $commentable->commentable;
     $commentType = $behavior->commentType;
     $comment = $this->loadModel($id, $commentType);
     if (!($uid = Yii::app()->user->id)) {
         throw new CHttpException(403);
     }
     $commentLikeType = $comment::$commentLikeType;
     $liked = CommentLike::model($commentLikeType)->findByPk(array('comment_id' => $id, 'user_id' => $uid));
     $trx = Comment::model()->getDbConnection()->beginTransaction();
     $dir = $liked ? -1 : 1;
     Comment::model($commentType)->updateCounters(array('votes_up' => $dir), "id=? " . ($liked ? ' AND votes_up>0' : ''), array($id));
     if ($liked) {
         $liked->delete();
     } else {
         $like = new $commentLikeType();
         $like->comment_id = $id;
         $like->user_id = $uid;
         $like->save();
     }
     $trx->commit();
     $res = array('likes' => $comment->votes_up + $dir, 'dir' => $dir);
     echo json_encode($res);
     Yii::app()->end();
 }
예제 #6
0
            ?>
"></span>
                                                <i class="icon-thumbs-up text-info"></i>
                                                <?php 
        } else {
            ?>
                                                <i class="icon-thumbs-down text-info" title="<?php 
            echo Yii::t('comment', 'Unlike');
            ?>
"></i>
                                                <?php 
        }
        ?>
                                        </div>
                                        <?php 
        $totalLikes = CommentLike::model()->countLike($comment['id']);
        ?>
                                        <div class="comment-total-like">+<?php 
        echo $totalLikes[0]['count'];
        ?>
</div>
                                    </button>

                                    <?php 
        if ($comment['level'] < $maxTreeLevel) {
            ?>
                                        <button class="btn-comment-reply" title="<?php 
            echo Yii::t('comment', 'Reply');
            ?>
">
                                            <div class="commentReply">
예제 #7
0
    ?>
</td>
                                <td><?php 
    echo Yii::app()->extraFunctions->getShortTitle($val['content'], 60);
    ?>
</td>
                                <td><?php 
    echo Yii::app()->extraFunctions->getShortTitle($val['post_title'], 60);
    ?>
</td>
                                <td><?php 
    echo Yii::app()->extraFunctions->getFormatDate($val['created_date']);
    ?>
</td>
                                <td><?php 
    $countLike = CommentLike::model()->countLike($val['id']);
    if ($countLike === NULL) {
        echo 0;
    } else {
        echo $countLike[0]['count'];
    }
    ?>
</td>
                                <td>
                                    <?php 
    echo Yii::t('comment', 'Inactive');
    ?>
                                </td>
                                <td><a class="edit" href='<?php 
    echo Yii::app()->createUrl(backend . '/comment/trash', array('id' => $val['id']));
    ?>
예제 #8
0
 public function dislike($id)
 {
     $type = Input::get('type');
     if ($type) {
         if ($type == 1) {
             $like = Like::wherePostId($id)->whereUserId(Auth::user()->id)->get()->count();
             $dislike = Dislike::wherePostId($id)->whereUserId(Auth::user()->id)->get()->count();
             if ($like || $dislike) {
                 return 'false';
             }
             $like = new Dislike();
             $like->post_id = $id;
             $like->user_id = Auth::user()->id;
             try {
                 if ($like->save()) {
                     DB::table('notifications')->where('type', '2')->where('post_id', $like->post_id)->update(array('seen' => 0, 'updated_at' => Carbon::now()));
                     return 'true';
                 }
             } catch (Exception $e) {
             }
         } elseif ($type == 2) {
             $like = CommentLike::whereCommentId($id)->whereUserId(Auth::user()->id)->get()->count();
             $dislike = CommentDislike::whereCommentId($id)->whereUserId(Auth::user()->id)->get()->count();
             if ($like || $dislike) {
                 return 'false';
             }
             $like = new CommentDislike();
             $like->comment_id = $id;
             $like->user_id = Auth::user()->id;
             try {
                 if ($like->save()) {
                     return 'true';
                 }
             } catch (Exception $e) {
             }
         }
     }
     return 'false';
 }
예제 #9
0
                        <th><?php 
echo Yii::t('comment', 'Like');
?>
</th>
                    </tr>
                    <tr>
                        <td><?php 
echo $model->post_id;
?>
</td>
                        <td><?php 
echo Yii::app()->extraFunctions->getFormatDate($model->created_date);
?>
</td>
                        <td><?php 
$totalLikes = CommentLike::model()->countLike($model->id);
echo $totalLikes[0]['count'];
?>
                        </td>

                    </tr>
                </table>
            </div>
            <footer class="twt-footer">
                <header><?php 
echo Yii::t('comment', 'CONTENT');
?>
:</header>
                <textarea readonly="true"><?php 
echo $model->content;
?>