2 declare(strict_types=1);
3 namespace wcf\system\user\activity\event;
4 use wcf\data\article\ViewableArticleList;
5 use wcf\data\comment\response\CommentResponseList;
6 use wcf\data\comment\CommentList;
7 use wcf\data\user\UserList;
8 use wcf\system\SingletonFactory;
12 * User activity event implementation for responses to article comments.
15 * @copyright 2001-2018 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\User\Activity\Event
20 class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
24 public function prepare(array $events) {
26 foreach ($events as $event) {
27 $responseIDs[] = $event->objectID;
31 $responseList = new CommentResponseList();
32 $responseList->setObjectIDs($responseIDs);
33 $responseList->readObjects();
34 $responses = $responseList->getObjects();
37 $commentIDs = $comments = [];
38 foreach ($responses as $response) {
39 $commentIDs[] = $response->commentID;
41 if (!empty($commentIDs)) {
42 $commentList = new CommentList();
43 $commentList->setObjectIDs($commentIDs);
44 $commentList->readObjects();
45 $comments = $commentList->getObjects();
49 $articleContentIDs = [];
50 foreach ($comments as $comment) {
51 $articleContentIDs[] = $comment->objectID;
54 $articles = $articleContentToArticle = [];
55 if (!empty($articleContentIDs)) {
56 $articleList = new ViewableArticleList();
57 $articleList->getConditionBuilder()->add("article.articleID IN (SELECT articleID FROM wcf".WCF_N."_article_content WHERE articleContentID IN (?))", [$articleContentIDs]);
58 $articleList->readObjects();
59 foreach ($articleList as $article) {
60 $articles[$article->articleID] = $article;
62 $articleContentToArticle[$article->getArticleContent()->articleContentID] = $article->articleID;
67 $userIDs = $users = [];
68 foreach ($comments as $comment) {
69 $userIDs[] = $comment->userID;
71 if (!empty($userIDs)) {
72 $userList = new UserList();
73 $userList->setObjectIDs($userIDs);
74 $userList->readObjects();
75 $users = $userList->getObjects();
79 foreach ($events as $event) {
80 if (isset($responses[$event->objectID])) {
81 $response = $responses[$event->objectID];
82 $comment = $comments[$response->commentID];
83 if (isset($articleContentToArticle[$comment->objectID]) && isset($users[$comment->userID])) {
84 $article = $articles[$articleContentToArticle[$comment->objectID]];
87 if (!$article->canRead()) {
90 $event->setIsAccessible();
93 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
94 'commentAuthor' => $users[$comment->userID],
95 'commentID' => $comment->commentID,
96 'responseID' => $response->responseID,
99 $event->setTitle($text);
102 $event->setDescription($response->getExcerpt());
107 $event->setIsOrphaned();