2 namespace wcf\system\user\activity\event;
3 use wcf\data\comment\response\CommentResponseList;
4 use wcf\data\comment\CommentList;
5 use wcf\data\page\PageCache;
6 use wcf\data\user\UserList;
7 use wcf\system\SingletonFactory;
11 * User activity event implementation for responses to page comments.
13 * @author Joshua Ruesweg
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
19 class PageCommentResponseUserActivityEvent 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;
41 if (!empty($commentIDs)) {
42 $commentList = new CommentList();
43 $commentList->setObjectIDs($commentIDs);
44 $commentList->readObjects();
45 $comments = $commentList->getObjects();
49 $userIDs = $users = [];
50 foreach ($comments as $comment) {
51 $userIDs[] = $comment->userID;
54 if (!empty($userIDs)) {
55 $userList = new UserList();
56 $userList->setObjectIDs($userIDs);
57 $userList->readObjects();
58 $users = $userList->getObjects();
62 foreach ($events as $event) {
63 if (isset($responses[$event->objectID])) {
64 $response = $responses[$event->objectID];
65 $comment = $comments[$response->commentID];
66 if (PageCache::getInstance()->getPage($comment->objectID) && isset($users[$comment->userID])) {
67 $page = PageCache::getInstance()->getPage($comment->objectID);
70 if (!$page->isAccessible()) {
73 $event->setIsAccessible();
76 $text = WCF::getLanguage()->getDynamicVariable('wcf.page.recentActivity.pageCommentResponse', [
77 'commentAuthor' => $users[$comment->userID],
78 'commentID' => $comment->commentID,
79 'responseID' => $response->responseID,
82 $event->setTitle($text);
85 $event->setDescription($response->getExcerpt());
90 $event->setIsOrphaned();