Added like/report support for page/articles comments
authorMarcel Werk <burntime@woltlab.com>
Thu, 16 Jun 2016 16:15:10 +0000 (18:15 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 16 Jun 2016 16:15:15 +0000 (18:15 +0200)
wcfsetup/install/files/lib/data/page/Page.class.php
wcfsetup/install/files/lib/system/box/PageCommentListBoxController.class.php
wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php
wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php

index 8296d6e4056cc5ce2b7a37c58750497fac17ca94..f450da8a4810fa192174c95bfdc67732977ccf32 100644 (file)
@@ -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.
         * 
index 768ba54e4ebc386871da34f0871c53b56f8c2731..b6b4eadc9a7e6999c5f59285a8d4060778ca6635 100644 (file)
@@ -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() : []),
                ]);
        }
        
index f8d126e912f424d54115c8530369d4fbbdd9a06c..32e8ad0c78a216448c44a684e403b57e46f83312 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 namespace wcf\system\comment\manager;
-use wcf\data\article\ArticleList;
 use wcf\data\article\content\ArticleContent;
 use wcf\data\article\ArticleEditor;
+use wcf\data\article\content\ArticleContentList;
 use wcf\data\comment\CommentList;
 use wcf\data\comment\response\CommentResponseList;
 use wcf\data\object\type\ObjectTypeCache;
@@ -44,6 +44,11 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL
         */
        protected $permissionModEdit = 'mod.article.canEditComment';
        
+       /**
+        * @inheritDoc
+        */
+       protected $permissionCanModerate = 'mod.article.canModerateComment';
+       
        /**
         * @inheritDoc
         */
@@ -124,9 +129,9 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL
                
                // fetch users
                $users = [];
-               $articleIDs = [];
+               $articleContentIDs = [];
                foreach ($comments as $comment) {
-                       $articleIDs[] = $comment->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;
-       }
 }
index 3656c2cf8a8d36e38c576f874586c7f7473c9807..7af5f21c2a598a6375203f2eed1099bb7bc34aec 100644 (file)
@@ -1,6 +1,14 @@
 <?php
 namespace wcf\system\comment\manager;
+use wcf\data\comment\CommentList;
+use wcf\data\comment\response\CommentResponseList;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\data\page\Page;
+use wcf\data\page\PageList;
+use wcf\system\cache\runtime\UserProfileRuntimeCache;
+use wcf\system\like\IViewableLikeProvider;
 use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
 
 /**
  * Page comment manager implementation.
@@ -10,7 +18,7 @@ use wcf\system\request\LinkHandler;
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @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());
+                                       }
+                               }
+                       }
+               }
        }
 }