checkComment($id); $user = $this->getCurrentUser(); return $this->handleComment($comment, $user); } protected function handleComment(CommentModel $comment, UserModel $user) { $toUser = $this->handleToUserInfo($comment->to_user_id); $owner = $this->handleOwnerInfo($comment->owner_id); $me = $this->handleMeInfo($comment, $user); return [ 'id' => $comment->id, 'content' => $comment->content, 'published' => $comment->published, 'deleted' => $comment->deleted, 'parent_id' => $comment->parent_id, 'like_count' => $comment->like_count, 'reply_count' => $comment->reply_count, 'create_time' => $comment->create_time, 'update_time' => $comment->update_time, 'to_user' => $toUser, 'owner' => $owner, 'me' => $me, ]; } protected function handleToUserInfo($userId) { if ($userId == 0) return null; $service = new ShallowUserInfo(); return $service->handle($userId); } protected function handleOwnerInfo($userId) { $service = new ShallowUserInfo(); return $service->handle($userId); } protected function handleMeInfo(CommentModel $comment, UserModel $user) { $me = [ 'logged' => 0, 'liked' => 0, 'owned' => 0, ]; if ($user->id == $comment->owner_id) { $me['owned'] = 1; } if ($user->id > 0) { $me['logged'] = 1; $likeRepo = new CommentLikeRepo(); $like = $likeRepo->findCommentLike($comment->id, $user->id); if ($like && $like->deleted == 0) { $me['liked'] = 1; } } return $me; } }