From: Marcel Werk Date: Thu, 16 Jun 2016 16:15:10 +0000 (+0200) Subject: Added like/report support for page/articles comments X-Git-Tag: 3.0.0_Beta_1~1414 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a6b1d3185e8ffe0eba0696d0021d484dd797d716;p=GitHub%2FWoltLab%2FWCF.git Added like/report support for page/articles comments --- diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index 8296d6e405..f450da8a48 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -219,6 +219,16 @@ class Page extends DatabaseObject implements ILinkableObject, ITitledObject { return true; } + /** + * Returns true if this page is accessible by current user. + * + * @return boolean + */ + public function isAccessible() { + // @todo + return true; + } + /** * Sets the current page as landing page. * diff --git a/wcfsetup/install/files/lib/system/box/PageCommentListBoxController.class.php b/wcfsetup/install/files/lib/system/box/PageCommentListBoxController.class.php index 768ba54e4e..b6b4eadc9a 100644 --- a/wcfsetup/install/files/lib/system/box/PageCommentListBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/PageCommentListBoxController.class.php @@ -38,7 +38,8 @@ class PageCommentListBoxController extends AbstractDatabaseObjectListBoxControll 'commentList' => $this->objectList, 'commentObjectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.page'), 'lastCommentTime' => $this->objectList->getMinCommentTime(), - 'pageID' => RequestHandler::getInstance()->getActiveRequest()->getPageID() + 'pageID' => RequestHandler::getInstance()->getActiveRequest()->getPageID(), + 'likeData' => ((MODULE_LIKE && $this->objectList) ? $this->objectList->getLikeData() : []), ]); } 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 f8d126e912..32e8ad0c78 100644 --- a/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php +++ b/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php @@ -1,8 +1,8 @@ objectID; + $articleContentIDs[] = $comment->objectID; if ($comment->userID) { $userIDs[] = $comment->userID; } @@ -136,12 +141,12 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL } // fetch articles - $articles = []; - if (!empty($articleIDs)) { - $articleList = new ArticleList(); - $articleList->setObjectIDs($articleIDs); - $articleList->readObjects(); - $articles = $articleList->getObjects(); + $articleContents = []; + if (!empty($articleContentIDs)) { + $articleContentList = new ArticleContentList(); + $articleContentList->setObjectIDs($articleContentIDs); + $articleContentList->readObjects(); + $articleContents = $articleContentList->getObjects(); } // set message @@ -151,13 +156,13 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL if (isset($comments[$like->objectID])) { $comment = $comments[$like->objectID]; - if (isset($articles[$comment->objectID]) && $articles[$comment->objectID]->canRead()) { + if (isset($articleContents[$comment->objectID]) && $articleContents[$comment->objectID]->getArticle()->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], + 'articleContent' => $articleContents[$comment->objectID], 'like' => $like ]); $like->setTitle($text); @@ -173,14 +178,14 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL $response = $responses[$like->objectID]; $comment = $comments[$response->commentID]; - if (isset($articles[$comment->objectID]) && $articles[$comment->objectID]->canRead()) { + if (isset($articleContents[$comment->objectID]) && $articleContents[$comment->objectID]->getArticle()->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], + 'articleContent' => $articleContents[$comment->objectID], 'like' => $like ]); $like->setTitle($text); @@ -192,12 +197,4 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL } } } - - /** - * @inheritDoc - */ - public function supportsReport() { - // @todo - return false; - } } diff --git a/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php b/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php index 3656c2cf8a..7af5f21c2a 100644 --- a/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php +++ b/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php @@ -1,6 +1,14 @@ * @package WoltLabSuite\Core\System\Comment\Manager */ -class PageCommentManager extends AbstractCommentManager { +class PageCommentManager extends AbstractCommentManager implements IViewableLikeProvider { /** * @inheritDoc */ @@ -36,11 +44,21 @@ class PageCommentManager extends AbstractCommentManager { */ protected $permissionModEdit = 'mod.pageComment.canEditComment'; + /** + * @inheritDoc + */ + protected $permissionCanModerate = 'mod.pageComment.canModerateComment'; + /** * @inheritDoc */ public function isAccessible($objectID, $validateWritePermission = false) { - // @todo + // check object id + $page = new Page($objectID); + if (!$page->pageID || !$page->isAccessible()) { + return false; + } + return true; } @@ -55,7 +73,9 @@ class PageCommentManager extends AbstractCommentManager { * @inheritDoc */ public function getTitle($objectTypeID, $objectID, $isResponse = false) { - return ''; + if ($isResponse) return WCF::getLanguage()->get('wcf.page.commentResponse'); + + return WCF::getLanguage()->getDynamicVariable('wcf.page.comment'); } /** @@ -66,14 +86,109 @@ class PageCommentManager extends AbstractCommentManager { /** * @inheritDoc */ - public function supportsLike() { - return false; - } - - /** - * @inheritDoc - */ - public function supportsReport() { - 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 = []; + $pageIDs = []; + foreach ($comments as $comment) { + $pageIDs[] = $comment->objectID; + if ($comment->userID) { + $userIDs[] = $comment->userID; + } + } + if (!empty($userIDs)) { + $users = UserProfileRuntimeCache::getInstance()->getObjects(array_unique($userIDs)); + } + + // fetch pages + $pages = []; + if (!empty($pageIDs)) { + $pageList = new PageList(); + $pageList->setObjectIDs($pageIDs); + $pageList->readObjects(); + $pages = $pageList->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($pages[$comment->objectID]) && $pages[$comment->objectID]->isAccessible()) { + $like->setIsAccessible(); + + // short output + $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.com.woltlab.wcf.pageComment', [ + 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, + 'page' => $pages[$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($pages[$comment->objectID]) && $pages[$comment->objectID]->isAccessible()) { + $like->setIsAccessible(); + + // short output + $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.com.woltlab.wcf.pageComment.response', [ + 'responseAuthor' => $comment->userID ? $users[$response->userID] : null, + 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, + 'page' => $pages[$comment->objectID], + 'like' => $like + ]); + $like->setTitle($text); + + // output + $like->setDescription($response->getExcerpt()); + } + } + } + } } }