Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / user / activity / event / ArticleCommentUserActivityEvent.class.php
1 <?php
2
3 namespace wcf\system\user\activity\event;
4
5 use wcf\data\article\ViewableArticleList;
6 use wcf\data\comment\CommentList;
7 use wcf\system\SingletonFactory;
8 use wcf\system\WCF;
9
10 /**
11 * User activity event implementation for article comments.
12 *
13 * @author Marcel Werk
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\User\Activity\Event
17 * @since 3.0
18 */
19 class ArticleCommentUserActivityEvent extends SingletonFactory implements IUserActivityEvent
20 {
21 /**
22 * @inheritDoc
23 */
24 public function prepare(array $events)
25 {
26 $commentIDs = [];
27 foreach ($events as $event) {
28 $commentIDs[] = $event->objectID;
29 }
30
31 // fetch comments
32 $commentList = new CommentList();
33 $commentList->setObjectIDs($commentIDs);
34 $commentList->readObjects();
35 $comments = $commentList->getObjects();
36
37 // fetch articles
38 $articleContentIDs = [];
39 foreach ($comments as $comment) {
40 $articleContentIDs[] = $comment->objectID;
41 }
42
43 $articles = $articleContentToArticle = [];
44 if (!empty($articleContentIDs)) {
45 $articleList = new ViewableArticleList();
46 $articleList->getConditionBuilder()->add(
47 "article.articleID IN (SELECT articleID FROM wcf" . WCF_N . "_article_content WHERE articleContentID IN (?))",
48 [$articleContentIDs]
49 );
50 $articleList->readObjects();
51 foreach ($articleList as $article) {
52 $articles[$article->articleID] = $article;
53
54 $articleContentToArticle[$article->getArticleContent()->articleContentID] = $article->articleID;
55 }
56 }
57
58 // set message
59 foreach ($events as $event) {
60 if (isset($comments[$event->objectID])) {
61 // short output
62 $comment = $comments[$event->objectID];
63 if (isset($articleContentToArticle[$comment->objectID])) {
64 $article = $articles[$articleContentToArticle[$comment->objectID]];
65
66 // check permissions
67 if (!$article->canRead()) {
68 continue;
69 }
70 $event->setIsAccessible();
71
72 // add title
73 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleComment', [
74 'article' => $article,
75 'commentID' => $comment->commentID,
76 ]);
77 $event->setTitle($text);
78
79 // add text
80 $event->setDescription($comment->getExcerpt());
81 continue;
82 }
83 }
84
85 $event->setIsOrphaned();
86 }
87 }
88 }