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;
11 * User activity event implementation for responses to article comments.
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
21 class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
25 public function prepare(array $events) {
27 foreach ($events as $event) {
28 $responseIDs[] = $event->objectID;
32 $responseList = new CommentResponseList();
33 $responseList->setObjectIDs($responseIDs);
34 $responseList->readObjects();
35 $responses = $responseList->getObjects();
38 $commentIDs = $comments = [];
39 foreach ($responses as $response) {
40 $commentIDs[] = $response->commentID;
42 if (!empty($commentIDs)) {
43 $commentList = new CommentList();
44 $commentList->setObjectIDs($commentIDs);
45 $commentList->readObjects();
46 $comments = $commentList->getObjects();
50 $articleIDs = $articles = [];
51 foreach ($comments as $comment) {
52 $articleIDs[] = $comment->objectID;
54 if (!empty($articleIDs)) {
55 $articleList = new ViewableArticleList();
56 $articleList->setObjectIDs($articleIDs);
57 $articleList->readObjects();
58 $articles = $articleList->getObjects();
62 $userIDs = $user = [];
63 foreach ($comments as $comment) {
64 $userIDs[] = $comment->userID;
66 if (!empty($userIDs)) {
67 $userList = new UserList();
68 $userList->setObjectIDs($userIDs);
69 $userList->readObjects();
70 $users = $userList->getObjects();
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];
82 if (!$article->canRead()) {
85 $event->setIsAccessible();
88 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
89 'commentAuthor' => $users[$comment->userID],
92 $event->setTitle($text);
95 $event->setDescription($response->getExcerpt());
100 $event->setIsOrphaned();