checkComment($id); $user = $this->getLoginUser(); $validator = new UserDailyLimitValidator(); $validator->checkCommentLikeLimit($user); $validator = new CommentValidator(); $commentLike = $validator->checkIfLiked($comment->id, $user->id); if (!$commentLike) { $commentLike = new CommentLikeModel(); $commentLike->create([ 'comment_id' => $comment->id, 'user_id' => $user->id, ]); $this->incrLikeCount($comment); } else { if ($commentLike->deleted == 0) { $commentLike->update(['deleted' => 1]); $this->decrLikeCount($comment); } else { $commentLike->update(['deleted' => 0]); $this->incrLikeCount($comment); } } $this->incrUserDailyCommentLikeCount($user); return $comment; } protected function incrLikeCount(CommentModel $comment) { $this->getPhEventsManager()->fire('commentCounter:incrLikeCount', $this, $comment); } protected function decrLikeCount(CommentModel $comment) { $this->getPhEventsManager()->fire('commentCounter:decrLikeCount', $this, $comment); } protected function incrUserDailyCommentLikeCount(UserModel $user) { $this->getPhEventsManager()->fire('userDailyCounter:incrCommentLikeCount', $this, $user); } /** * @return EventsManager */ protected function getPhEventsManager() { return $this->getDI()->get('eventsManager'); } }