From: Marcel Werk Date: Thu, 16 Jun 2016 11:33:42 +0000 (+0200) Subject: Added like support for article comments X-Git-Tag: 3.0.0_Beta_1~1421 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4a4b6f59d7726e54c42cacace614215dc7434b20;p=GitHub%2FWoltLab%2FWCF.git Added like support for article comments --- diff --git a/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php b/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php index 623e3771cf..f8d126e912 100644 --- a/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php +++ b/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php @@ -1,7 +1,13 @@ * @package WoltLabSuite\Core\System\Comment\Manager */ -class ArticleCommentManager extends AbstractCommentManager { +class ArticleCommentManager extends AbstractCommentManager implements IViewableLikeProvider { /** * @inheritDoc */ @@ -81,9 +87,110 @@ class ArticleCommentManager extends AbstractCommentManager { /** * @inheritDoc */ - public function supportsLike() { - // @todo - return false; + public function prepare(array $likes) { + $commentLikeObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.like.likeableObject', 'com.woltlab.wcf.comment'); + + $commentIDs = $responseIDs = []; + foreach ($likes as $like) { + if ($like->objectTypeID == $commentLikeObjectType->objectTypeID) { + $commentIDs[] = $like->objectID; + } + else { + $responseIDs[] = $like->objectID; + } + } + + // fetch response + $userIDs = $responses = []; + if (!empty($responseIDs)) { + $responseList = new CommentResponseList(); + $responseList->setObjectIDs($responseIDs); + $responseList->readObjects(); + $responses = $responseList->getObjects(); + + foreach ($responses as $response) { + $commentIDs[] = $response->commentID; + if ($response->userID) { + $userIDs[] = $response->userID; + } + } + } + + // fetch comments + $commentList = new CommentList(); + $commentList->setObjectIDs($commentIDs); + $commentList->readObjects(); + $comments = $commentList->getObjects(); + + // fetch users + $users = []; + $articleIDs = []; + foreach ($comments as $comment) { + $articleIDs[] = $comment->objectID; + if ($comment->userID) { + $userIDs[] = $comment->userID; + } + } + if (!empty($userIDs)) { + $users = UserProfileRuntimeCache::getInstance()->getObjects(array_unique($userIDs)); + } + + // fetch articles + $articles = []; + if (!empty($articleIDs)) { + $articleList = new ArticleList(); + $articleList->setObjectIDs($articleIDs); + $articleList->readObjects(); + $articles = $articleList->getObjects(); + } + + // set message + foreach ($likes as $like) { + if ($like->objectTypeID == $commentLikeObjectType->objectTypeID) { + // comment like + if (isset($comments[$like->objectID])) { + $comment = $comments[$like->objectID]; + + if (isset($articles[$comment->objectID]) && $articles[$comment->objectID]->canRead()) { + $like->setIsAccessible(); + + // short output + $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.com.woltlab.wcf.articleComment', [ + 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, + 'article' => $articles[$comment->objectID], + 'like' => $like + ]); + $like->setTitle($text); + + // output + $like->setDescription($comment->getExcerpt()); + } + } + } + else { + // response like + if (isset($responses[$like->objectID])) { + $response = $responses[$like->objectID]; + $comment = $comments[$response->commentID]; + + if (isset($articles[$comment->objectID]) && $articles[$comment->objectID]->canRead()) { + $like->setIsAccessible(); + + // short output + $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.com.woltlab.wcf.articleComment.response', [ + 'responseAuthor' => $comment->userID ? $users[$response->userID] : null, + 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, + 'article' => $articles[$comment->objectID], + 'like' => $like + ]); + $like->setTitle($text); + + // output + $like->setDescription($response->getExcerpt()); + } + } + } + } } /**