Exemplo n.º 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;
 }
 public function actionLoadComments($book_id, $offset)
 {
     $comments = BooksComments::model()->findAll(array('condition' => 'book_id = :bookId', 'order' => 'id DESC', 'offset' => intval($offset), 'limit' => '10', 'params' => array(':bookId' => $book_id)));
     foreach ($comments as $comment) {
         $this->renderPartial('_comment', array('comment' => $comment));
     }
 }