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