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-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
19 class ArticleCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
23 public function prepare(array $events) {
25 foreach ($events as $event) {
26 $responseIDs[] = $event->objectID;
30 $responseList = new CommentResponseList();
31 $responseList->setObjectIDs($responseIDs);
32 $responseList->readObjects();
33 $responses = $responseList->getObjects();
36 $commentIDs = $comments = [];
37 foreach ($responses as $response) {
38 $commentIDs[] = $response->commentID;
40 if (!empty($commentIDs)) {
41 $commentList = new CommentList();
42 $commentList->setObjectIDs($commentIDs);
43 $commentList->readObjects();
44 $comments = $commentList->getObjects();
48 $articleIDs = $articles = [];
49 foreach ($comments as $comment) {
50 $articleIDs[] = $comment->objectID;
52 if (!empty($articleIDs)) {
53 $articleList = new ViewableArticleList();
54 $articleList->setObjectIDs($articleIDs);
55 $articleList->readObjects();
56 $articles = $articleList->getObjects();
60 $userIDs = $users = [];
61 foreach ($comments as $comment) {
62 $userIDs[] = $comment->userID;
64 if (!empty($userIDs)) {
65 $userList = new UserList();
66 $userList->setObjectIDs($userIDs);
67 $userList->readObjects();
68 $users = $userList->getObjects();
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];
80 if (!$article->canRead()) {
83 $event->setIsAccessible();
86 $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity.articleCommentResponse', [
87 'commentAuthor' => $users[$comment->userID],
88 'commentID' => $comment->commentID,
89 'responseID' => $response->responseID,
92 $event->setTitle($text);
95 $event->setDescription($response->getExcerpt());
100 $event->setIsOrphaned();