public function wasLiked() { $model = CommentToCommentLike::model()->findByAttributes(array('commen_to_comment_id' => $this->id, 'user_id' => Yii::app()->user->id)); if (empty($model)) { return 0; } return $model->value; }
public function actionSetCommentToCommentLike($comment_id, $val) { /* * @var BooksCommentToComment $comment * */ $result = array(); $comment = BooksCommentToComment::model()->findByPk($comment_id); $result['status'] = CommentToCommentLike::setCommentLike($comment_id, $val); $result['like'] = $comment->getLike(); $result['dislike'] = $comment->getLike('-'); echo json_encode($result); }
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; }