90ef2474b3b46d15521295e5b095d2c313f42358
[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-2017 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 $articleIDs = $articles = [];
49 foreach ($comments as $comment) {
50 $articleIDs[] = $comment->objectID;
51 }
52 if (!empty($articleIDs)) {
53 $articleList = new ViewableArticleList();
54 $articleList->setObjectIDs($articleIDs);
55 $articleList->readObjects();
56 $articles = $articleList->getObjects();
57 }
58
59 // fetch users
60 $userIDs = $users = [];
61 foreach ($comments as $comment) {
62 $userIDs[] = $comment->userID;
63 }
64 if (!empty($userIDs)) {
65 $userList = new UserList();
66 $userList->setObjectIDs($userIDs);
67 $userList->readObjects();
68 $users = $userList->getObjects();
69 }
70
71 // set message
72 foreach ($events as $event) {
73 if (isset($responses[$event->objectID])) {
74 $response = $responses[$event->objectID];
75 $comment = $comments[$response->commentID];
76 if (isset($articles[$comment->objectID]) && isset($users[$comment->userID])) {
77 $article = $articles[$comment->objectID];
78
79 // check permissions
80 if (!$article->canRead()) {
81 continue;
82 }
83 $event->setIsAccessible();
84
85 // title
86 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
87 'commentAuthor' => $users[$comment->userID],
88 'commentID' => $comment->commentID,
89 'responseID' => $response->responseID,
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 }