2025e7434b58a6b305a553ac2b39b8ab900e14e8
[GitHub/WoltLab/WCF.git] /
1 <?php
2 declare(strict_types=1);
3 namespace wcf\system\user\activity\event;
4 use wcf\data\comment\response\CommentResponseList;
5 use wcf\data\comment\CommentList;
6 use wcf\system\cache\runtime\UserProfileRuntimeCache;
7 use wcf\system\SingletonFactory;
8 use wcf\system\WCF;
9
10 /**
11 * User activity event implementation for profile comment responses.
12 *
13 * @author Marcel Werk
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
17 */
18 class ProfileCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
19 /**
20 * @inheritDoc
21 */
22 public function prepare(array $events) {
23 if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
24 return;
25 }
26
27 $responseIDs = [];
28 foreach ($events as $event) {
29 $responseIDs[] = $event->objectID;
30 }
31
32 // fetch responses
33 $responseList = new CommentResponseList();
34 $responseList->setObjectIDs($responseIDs);
35 $responseList->readObjects();
36 $responses = $responseList->getObjects();
37
38 // fetch comments
39 $commentIDs = $comments = [];
40 foreach ($responses as $response) {
41 $commentIDs[] = $response->commentID;
42 }
43 if (!empty($commentIDs)) {
44 $commentList = new CommentList();
45 $commentList->setObjectIDs($commentIDs);
46 $commentList->readObjects();
47 $comments = $commentList->getObjects();
48 }
49
50 // fetch users
51 $userIDs = $users = [];
52 foreach ($comments as $comment) {
53 $userIDs[] = $comment->objectID;
54 $userIDs[] = $comment->userID;
55 }
56 if (!empty($userIDs)) {
57 $users = UserProfileRuntimeCache::getInstance()->getObjects($userIDs);
58 }
59
60 // set message
61 foreach ($events as $event) {
62 if (isset($responses[$event->objectID])) {
63 $response = $responses[$event->objectID];
64 $comment = $comments[$response->commentID];
65 if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) {
66 if (!$users[$comment->objectID]->isProtected()) {
67 $event->setIsAccessible();
68
69 // title
70 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', [
71 'commentAuthor' => $users[$comment->userID],
72 'commentID' => $comment->commentID,
73 'responseID' => $response->responseID,
74 'user' => $users[$comment->objectID]
75 ]);
76 $event->setTitle($text);
77
78 // description
79 $event->setDescription($response->getExcerpt());
80 }
81 continue;
82 }
83 }
84
85 $event->setIsOrphaned();
86 }
87 }
88 }