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;
11 * User activity event implementation for profile comment responses.
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
18 class ProfileCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
22 public function prepare(array $events) {
23 if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
28 foreach ($events as $event) {
29 $responseIDs[] = $event->objectID;
33 $responseList = new CommentResponseList();
34 $responseList->setObjectIDs($responseIDs);
35 $responseList->readObjects();
36 $responses = $responseList->getObjects();
39 $commentIDs = $comments = [];
40 foreach ($responses as $response) {
41 $commentIDs[] = $response->commentID;
43 if (!empty($commentIDs)) {
44 $commentList = new CommentList();
45 $commentList->setObjectIDs($commentIDs);
46 $commentList->readObjects();
47 $comments = $commentList->getObjects();
51 $userIDs = $users = [];
52 foreach ($comments as $comment) {
53 $userIDs[] = $comment->objectID;
54 $userIDs[] = $comment->userID;
56 if (!empty($userIDs)) {
57 $users = UserProfileRuntimeCache::getInstance()->getObjects($userIDs);
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();
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]
76 $event->setTitle($text);
79 $event->setDescription($response->getExcerpt());
85 $event->setIsOrphaned();