9a24521845b01699d91696b70034a28de991ff11
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\activity\event;
3 use wcf\data\article\ViewableArticleList;
4 use wcf\data\comment\response\CommentResponseList;
5 use wcf\data\comment\CommentList;
6 use wcf\data\user\UserList;
7 use wcf\system\SingletonFactory;
8 use wcf\system\WCF;
9
10 /**
11 * User activity event implementation for responses to article comments.
12 *
13 * @author Marcel Werk
14 * @copyright 2001-2018 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 ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
20 /**
21 * @inheritDoc
22 */
23 public function prepare(array $events) {
24 $responseIDs = [];
25 foreach ($events as $event) {
26 $responseIDs[] = $event->objectID;
27 }
28
29 // fetch responses
30 $responseList = new CommentResponseList();
31 $responseList->setObjectIDs($responseIDs);
32 $responseList->readObjects();
33 $responses = $responseList->getObjects();
34
35 // fetch comments
36 $commentIDs = $comments = [];
37 foreach ($responses as $response) {
38 $commentIDs[] = $response->commentID;
39 }
40 if (!empty($commentIDs)) {
41 $commentList = new CommentList();
42 $commentList->setObjectIDs($commentIDs);
43 $commentList->readObjects();
44 $comments = $commentList->getObjects();
45 }
46
47 // fetch articles
48 $articleContentIDs = [];
49 foreach ($comments as $comment) {
50 $articleContentIDs[] = $comment->objectID;
51 }
52
53 $articles = $articleContentToArticle = [];
54 if (!empty($articleContentIDs)) {
55 $articleList = new ViewableArticleList();
56 $articleList->getConditionBuilder()->add("article.articleID IN (SELECT articleID FROM wcf".WCF_N."_article_content WHERE articleContentID IN (?))", [$articleContentIDs]);
57 $articleList->readObjects();
58 foreach ($articleList as $article) {
59 $articles[$article->articleID] = $article;
60
61 $articleContentToArticle[$article->getArticleContent()->articleContentID] = $article->articleID;
62 }
63 }
64
65 // fetch users
66 $userIDs = $users = [];
67 foreach ($comments as $comment) {
68 $userIDs[] = $comment->userID;
69 }
70 if (!empty($userIDs)) {
71 $userList = new UserList();
72 $userList->setObjectIDs($userIDs);
73 $userList->readObjects();
74 $users = $userList->getObjects();
75 }
76
77 // set message
78 foreach ($events as $event) {
79 if (isset($responses[$event->objectID])) {
80 $response = $responses[$event->objectID];
81 $comment = $comments[$response->commentID];
82 if (isset($articleContentToArticle[$comment->objectID]) && isset($users[$comment->userID])) {
83 $article = $articles[$articleContentToArticle[$comment->objectID]];
84
85 // check permissions
86 if (!$article->canRead()) {
87 continue;
88 }
89 $event->setIsAccessible();
90
91 // title
92 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
93 'commentAuthor' => $users[$comment->userID],
94 'commentID' => $comment->commentID,
95 'responseID' => $response->responseID,
96 'article' => $article
97 ]);
98 $event->setTitle($text);
99
100 // description
101 $event->setDescription($response->getExcerpt());
102 continue;
103 }
104 }
105
106 $event->setIsOrphaned();
107 }
108 }
109 }