fd04a6d20cbb29634d10f444abd926a9481e6772
[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-2016 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage system.user.activity.event
18 * @category Community Framework
19 * @since 2.2
20 */
21 class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
22 /**
23 * @inheritDoc
24 */
25 public function prepare(array $events) {
26 $responseIDs = [];
27 foreach ($events as $event) {
28 $responseIDs[] = $event->objectID;
29 }
30
31 // fetch responses
32 $responseList = new CommentResponseList();
33 $responseList->setObjectIDs($responseIDs);
34 $responseList->readObjects();
35 $responses = $responseList->getObjects();
36
37 // fetch comments
38 $commentIDs = $comments = [];
39 foreach ($responses as $response) {
40 $commentIDs[] = $response->commentID;
41 }
42 if (!empty($commentIDs)) {
43 $commentList = new CommentList();
44 $commentList->setObjectIDs($commentIDs);
45 $commentList->readObjects();
46 $comments = $commentList->getObjects();
47 }
48
49 // fetch articles
50 $articleIDs = $articles = [];
51 foreach ($comments as $comment) {
52 $articleIDs[] = $comment->objectID;
53 }
54 if (!empty($articleIDs)) {
55 $articleList = new ViewableArticleList();
56 $articleList->setObjectIDs($articleIDs);
57 $articleList->readObjects();
58 $articles = $articleList->getObjects();
59 }
60
61 // fetch users
62 $userIDs = $user = [];
63 foreach ($comments as $comment) {
64 $userIDs[] = $comment->userID;
65 }
66 if (!empty($userIDs)) {
67 $userList = new UserList();
68 $userList->setObjectIDs($userIDs);
69 $userList->readObjects();
70 $users = $userList->getObjects();
71 }
72
73 // set message
74 foreach ($events as $event) {
75 if (isset($responses[$event->objectID])) {
76 $response = $responses[$event->objectID];
77 $comment = $comments[$response->commentID];
78 if (isset($articles[$comment->objectID]) && isset($users[$comment->userID])) {
79 $article = $articles[$comment->objectID];
80
81 // check permissions
82 if (!$article->canRead()) {
83 continue;
84 }
85 $event->setIsAccessible();
86
87 // title
88 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
89 'commentAuthor' => $users[$comment->userID],
90 'article' => $article
91 ]);
92 $event->setTitle($text);
93
94 // description
95 $event->setDescription($response->getExcerpt());
96 continue;
97 }
98 }
99
100 $event->setIsOrphaned();
101 }
102 }
103 }