コード例 #1
0
 public static function setCommentLike($id, $val)
 {
     $val = $val >= 0 ? 1 : -1;
     $rate = self::model()->findByAttributes(array('commen_to_comment_id' => $id, 'user_id' => Yii::app()->user->id));
     if (empty($rate)) {
         $rate = new CommentToCommentLike();
         $rate->commen_to_comment_id = $id;
         $rate->user_id = Yii::app()->user->id;
     } else {
         if ($rate->value == $val) {
             $rate->delete();
             return 0;
         }
     }
     $rate->value = $val;
     $rate->save();
     $comment = BooksCommentToComment::model()->findByPk($id);
     if (!empty($comment)) {
         $comment->updateRate();
     }
     return $val;
 }