From: Marcel Werk Date: Thu, 9 Jun 2016 14:37:37 +0000 (+0200) Subject: Added recent activity events for article comments X-Git-Tag: 3.0.0_Beta_1~1471 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=62e2632ace279adc0f5c56796ee3df883777c4e0;p=GitHub%2FWoltLab%2FWCF.git Added recent activity events for article comments --- diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index f2cd197e12..15679a9145 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -44,6 +44,16 @@ com.woltlab.wcf.user.recentActivityEvent wcf\system\user\activity\event\LikeableArticleUserActivityEvent + + com.woltlab.wcf.articleComment.recentActivityEvent + com.woltlab.wcf.user.recentActivityEvent + wcf\system\user\activity\event\ArticleCommentUserActivityEvent + + + com.woltlab.wcf.articleComment.response.recentActivityEvent + com.woltlab.wcf.user.recentActivityEvent + wcf\system\user\activity\event\ArticleCommentResponseUserActivityEvent + com.woltlab.wcf.article com.woltlab.wcf.searchableObjectType @@ -187,7 +197,7 @@ - com.woltlab.wcf.article + com.woltlab.wcf.articleComment com.woltlab.wcf.comment.commentableContent diff --git a/wcfsetup/install/files/lib/data/article/ArticleAction.class.php b/wcfsetup/install/files/lib/data/article/ArticleAction.class.php index 8fc73b8bcc..b5dc18ded1 100644 --- a/wcfsetup/install/files/lib/data/article/ArticleAction.class.php +++ b/wcfsetup/install/files/lib/data/article/ArticleAction.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/page/ArticlePage.class.php b/wcfsetup/install/files/lib/page/ArticlePage.class.php index fcbae6e6ac..d24a92259b 100644 --- a/wcfsetup/install/files/lib/page/ArticlePage.class.php +++ b/wcfsetup/install/files/lib/page/ArticlePage.class.php @@ -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 index 0000000000..fd04a6d20c --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php @@ -0,0 +1,103 @@ + + * @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 index 0000000000..8c6e0f4c74 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php @@ -0,0 +1,74 @@ + + * @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(); + } + } +} diff --git a/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php index e551306286..7e26cbc1c8 100644 --- a/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/ArticleRebuildDataWorker.class.php @@ -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 = ? diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 370076461e..2cb403bdd1 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1742,6 +1742,8 @@ Sie können jetzt den vollen Funktionsumfang der Seite nutzen.]]> comments} Kommentar{if $article->comments != 1}e{/if}]]> views} mal gelesen]]> getLink()}">{$article->getTitle()}.]]> + getLink()}#comments">{$article->getTitle()} geschrieben.]]> + {$commentAuthor->username} zum Artikel {$article->getTitle()} geantwortet.]]> @@ -2968,6 +2970,8 @@ Sollten Sie sich nicht auf der Website: {@PAGE_TITLE|language} angemeldet haben, + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index c2c80ec3cc..d6a0f202ae 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1749,6 +1749,8 @@ You can now fully access the website.]]> comments} Comment{if $article->comments != 1}s{/if}]]> views} View{if $article->views != 1}s{/if}]]> getLink()}">{$article->getTitle()}.]]> + getLink()}">{$article->getTitle()}.]]> + {$commentAuthor->username} on article {$article->getTitle()}.]]> @@ -3001,6 +3003,8 @@ You can safely ignore this email if you did not register with the website: {@PAG + +