Added recent activity events for article comments
authorMarcel Werk <burntime@woltlab.com>
Thu, 9 Jun 2016 14:37:37 +0000 (16:37 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 9 Jun 2016 14:37:37 +0000 (16:37 +0200)
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/data/article/ArticleAction.class.php
wcfsetup/install/files/lib/page/ArticlePage.class.php
wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index f2cd197e12105b9f92c019586e0f0de91000a5ba..15679a9145105e0b07c7882335fe6c5065a705d7 100644 (file)
                        <definitionname>com.woltlab.wcf.user.recentActivityEvent</definitionname>
                        <classname>wcf\system\user\activity\event\LikeableArticleUserActivityEvent</classname>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.articleComment.recentActivityEvent</name>
+                       <definitionname>com.woltlab.wcf.user.recentActivityEvent</definitionname>
+                       <classname>wcf\system\user\activity\event\ArticleCommentUserActivityEvent</classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.articleComment.response.recentActivityEvent</name>
+                       <definitionname>com.woltlab.wcf.user.recentActivityEvent</definitionname>
+                       <classname>wcf\system\user\activity\event\ArticleCommentResponseUserActivityEvent</classname>
+               </type>
                <type>
                        <name>com.woltlab.wcf.article</name>
                        <definitionname>com.woltlab.wcf.searchableObjectType</definitionname>
                </type>
                
                <type>
-                       <name>com.woltlab.wcf.article</name>
+                       <name>com.woltlab.wcf.articleComment</name>
                        <definitionname>com.woltlab.wcf.comment.commentableContent</definitionname>
                        <classname><![CDATA[wcf\system\comment\manager\ArticleCommentManager]]></classname>
                </type>
index 8fc73b8bccffb5c4b32c99c00a51f676f64c3ed4..b5dc18ded1ccdfddf6dcfd0a975d289ec4f39929 100644 (file)
@@ -152,7 +152,7 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                        // delete like data
                        LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.likeableArticle', $articleIDs);
                        // delete comments
-                       CommentHandler::getInstance()->deleteObjects('com.woltlab.wcf.article', $articleContentIDs);
+                       CommentHandler::getInstance()->deleteObjects('com.woltlab.wcf.articleComment', $articleContentIDs);
                        // delete tag to object entries
                        TagEngine::getInstance()->deleteObjects('com.woltlab.wcf.article', $articleContentIDs);
                        // delete entry from search index
index fcbae6e6ac912a5fc6e49aafb1f5e8b022401c9b..d24a92259b1455830bd264edc28c704a2e0e469e 100644 (file)
@@ -144,7 +144,7 @@ class ArticlePage extends AbstractPage {
                
                // get comments
                if ($this->article->enableComments) {
-                       $this->commentObjectTypeID = CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.article');
+                       $this->commentObjectTypeID = CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.articleComment');
                        $this->commentManager = CommentHandler::getInstance()->getObjectType($this->commentObjectTypeID)->getProcessor();
                        $this->commentList = CommentHandler::getInstance()->getCommentList($this->commentManager, $this->commentObjectTypeID, $this->articleContent->articleContentID);
                }
diff --git a/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php
new file mode 100644 (file)
index 0000000..fd04a6d
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+namespace wcf\system\user\activity\event;
+use wcf\data\article\ViewableArticleList;
+use wcf\data\comment\response\CommentResponseList;
+use wcf\data\comment\CommentList;
+use wcf\data\user\UserList;
+use wcf\system\SingletonFactory;
+use wcf\system\WCF;
+
+/**
+ * User activity event implementation for responses to article comments.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.user.activity.event
+ * @category   Community Framework
+ * @since       2.2
+ */
+class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
+       /**
+        * @inheritDoc
+        */
+       public function prepare(array $events) {
+               $responseIDs = [];
+               foreach ($events as $event) {
+                       $responseIDs[] = $event->objectID;
+               }
+               
+               // fetch responses
+               $responseList = new CommentResponseList();
+               $responseList->setObjectIDs($responseIDs);
+               $responseList->readObjects();
+               $responses = $responseList->getObjects();
+               
+               // fetch comments
+               $commentIDs = $comments = [];
+               foreach ($responses as $response) {
+                       $commentIDs[] = $response->commentID;
+               }
+               if (!empty($commentIDs)) {
+                       $commentList = new CommentList();
+                       $commentList->setObjectIDs($commentIDs);
+                       $commentList->readObjects();
+                       $comments = $commentList->getObjects();
+               }
+               
+               // fetch articles
+               $articleIDs = $articles = [];
+               foreach ($comments as $comment) {
+                       $articleIDs[] = $comment->objectID;
+               }
+               if (!empty($articleIDs)) {
+                       $articleList = new ViewableArticleList();
+                       $articleList->setObjectIDs($articleIDs);
+                       $articleList->readObjects();
+                       $articles = $articleList->getObjects();
+               }
+               
+               // fetch users
+               $userIDs = $user = [];
+               foreach ($comments as $comment) {
+                       $userIDs[] = $comment->userID;
+               }
+               if (!empty($userIDs)) {
+                       $userList = new UserList();
+                       $userList->setObjectIDs($userIDs);
+                       $userList->readObjects();
+                       $users = $userList->getObjects();
+               }
+               
+               // set message
+               foreach ($events as $event) {
+                       if (isset($responses[$event->objectID])) {
+                               $response = $responses[$event->objectID];
+                               $comment = $comments[$response->commentID];
+                               if (isset($articles[$comment->objectID]) && isset($users[$comment->userID])) {
+                                       $article = $articles[$comment->objectID];
+                                       
+                                       // check permissions
+                                       if (!$article->canRead()) {
+                                               continue;
+                                       }
+                                       $event->setIsAccessible();
+                                       
+                                       // title
+                                       $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
+                                               'commentAuthor' => $users[$comment->userID],
+                                               'article' => $article
+                                       ]);
+                                       $event->setTitle($text);
+                                       
+                                       // description
+                                       $event->setDescription($response->getExcerpt());
+                                       continue;
+                               }
+                       }
+                       
+                       $event->setIsOrphaned();
+               }
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php
new file mode 100644 (file)
index 0000000..8c6e0f4
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+namespace wcf\system\user\activity\event;
+use wcf\data\article\ViewableArticleList;
+use wcf\data\comment\CommentList;
+use wcf\system\SingletonFactory;
+use wcf\system\WCF;
+
+/**
+ * User activity event implementation for article comments.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.user.activity.event
+ * @category   Community Framework
+ * @since       2.2
+ */
+class ArticleCommentUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
+       /**
+        * @inheritDoc
+        */
+       public function prepare(array $events) {
+               $commentIDs = [];
+               foreach ($events as $event) {
+                       $commentIDs[] = $event->objectID;
+               }
+               
+               // fetch comments
+               $commentList = new CommentList();
+               $commentList->setObjectIDs($commentIDs);
+               $commentList->readObjects();
+               $comments = $commentList->getObjects();
+               
+               // fetch articles
+               $articleIDs = $articles = [];
+               foreach ($comments as $comment) {
+                       $articleIDs[] = $comment->objectID;
+               }
+               if (!empty($articleIDs)) {
+                       $articleList = new ViewableArticleList();
+                       $articleList->setObjectIDs($articleIDs);
+                       $articleList->readObjects();
+                       $articles = $articleList->getObjects();
+               }
+               
+               // set message
+               foreach ($events as $event) {
+                       if (isset($comments[$event->objectID])) {
+                               // short output
+                               $comment = $comments[$event->objectID];
+                               if (isset($articles[$comment->objectID])) {
+                                       $article = $articles[$comment->objectID];
+                                       
+                                       // check permissions
+                                       if (!$article->canRead()) {
+                                               continue;
+                                       }
+                                       $event->setIsAccessible();
+                                       
+                                       // add title
+                                       $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleComment', ['article' => $article]);
+                                       $event->setTitle($text);
+                                       
+                                       // add text
+                                       $event->setDescription($comment->getExcerpt());
+                                       continue;
+                               }
+                       }
+                       
+                       $event->setIsOrphaned();
+               }
+       }
+}
index e551306286bacc267527054b7408249372620dbe..7e26cbc1c844d78f6020a5f59ac488d79e800de8 100644 (file)
@@ -55,7 +55,7 @@ class ArticleRebuildDataWorker extends AbstractRebuildDataWorker {
                }
                $articles = $this->objectList->getObjects();
                
-               $commentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', 'com.woltlab.wcf.article');
+               $commentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', 'com.woltlab.wcf.articleComment');
                $sql = "SELECT  COUNT(*) AS comments, SUM(responses) AS responses
                        FROM    wcf".WCF_N."_comment
                        WHERE   objectTypeID = ?
index 370076461e0a7af773dd06523f014943bf24899e..2cb403bdd1efeeefcee3628769555a9e4db31f66 100644 (file)
@@ -1742,6 +1742,8 @@ Sie können jetzt den vollen Funktionsumfang der Seite nutzen.]]></item>
                <item name="wcf.article.articleComments"><![CDATA[{#$article->comments} Kommentar{if $article->comments != 1}e{/if}]]></item>
                <item name="wcf.article.articleViews"><![CDATA[{#$article->views} mal gelesen]]></item>
                <item name="wcf.article.recentActivity.likedArticle"><![CDATA[Mag den Artikel <a href="{$article->getLink()}">{$article->getTitle()}</a>.]]></item>
+               <item name="wcf.article.recentActivity.articleComment"><![CDATA[Hat einen Kommentar zum Artikel <a href="{$article->getLink()}#comments">{$article->getTitle()}</a> geschrieben.]]></item>
+               <item name="wcf.article.recentActivity.articleCommentResponse"><![CDATA[Hat auf einen Kommentar von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a> zum Artikel <a href="{$article->getLink()}#comments">{$article->getTitle()}</a> geantwortet.]]></item>
        </category>
        
        <category name="wcf.attachment">
@@ -2968,6 +2970,8 @@ Sollten Sie sich nicht auf der Website: {@PAGE_TITLE|language} angemeldet haben,
                <item name="wcf.user.recentActivity.com.woltlab.wcf.user.profileComment.recentActivityEvent"><![CDATA[Pinnwand-Kommentar]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.user.profileComment.response.recentActivityEvent"><![CDATA[Pinnwand-Antwort]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.likeableArticle.recentActivityEvent"><![CDATA[Like (Artikel)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.recentActivityEvent"><![CDATA[Kommentar (Artikel)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.response.recentActivityEvent"><![CDATA[Antwort (Artikel)]]></item>
                <item name="wcf.user.recentActivity.scope.all"><![CDATA[Aktivitäten aller Benutzer]]></item>
                <item name="wcf.user.recentActivity.scope.followedUsers"><![CDATA[Aktivitäten von Benutzern, denen Sie folgen]]></item>
        </category>
index c2c80ec3cc7667fbdbdaefbc8bc66b905cd025c1..d6a0f202aec05ad0f6998564b4c19a2f57e29c59 100644 (file)
@@ -1749,6 +1749,8 @@ You can now fully access the website.]]></item>
                <item name="wcf.article.articleComments"><![CDATA[{#$article->comments} Comment{if $article->comments != 1}s{/if}]]></item>
                <item name="wcf.article.articleViews"><![CDATA[{#$article->views} View{if $article->views != 1}s{/if}]]></item>
                <item name="wcf.article.recentActivity.likedArticle"><![CDATA[Liked the article <a href="{$article->getLink()}">{$article->getTitle()}</a>.]]></item>
+               <item name="wcf.article.recentActivity.articleComment"><![CDATA[Commented on article <a href="{$article->getLink()}">{$article->getTitle()}</a>.]]></item>
+               <item name="wcf.article.recentActivity.articleCommentResponse"><![CDATA[Replied to a comment by <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a> on article <a href="{$article->getLink()}">{$article->getTitle()}</a>.]]></item>
        </category>
        
        <category name="wcf.attachment">
@@ -3001,6 +3003,8 @@ You can safely ignore this email if you did not register with the website: {@PAG
                <item name="wcf.user.recentActivity.com.woltlab.wcf.user.profileComment.recentActivityEvent"><![CDATA[Wall Comment]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.user.profileComment.response.recentActivityEvent"><![CDATA[Wall Reply]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.likeableArticle.recentActivityEvent"><![CDATA[Like (Article)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.recentActivityEvent"><![CDATA[Comment (Article)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.articleComment.response.recentActivityEvent"><![CDATA[Reply (Article)]]></item>
                <item name="wcf.user.recentActivity.scope.all"><![CDATA[All Activities]]></item>
                <item name="wcf.user.recentActivity.scope.followedUsers"><![CDATA[Filter by Followed Users]]></item>
        </category>