a9a58be2234b0d04f7f50130a01f781fc7162a84
[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\data\user\UserProfileList;
6 use wcf\system\user\activity\event\IUserActivityEvent;
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-2015 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage system.user.activity.event
18 * @category Community Framework
19 */
20 class ProfileCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
21 /**
22 * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare()
23 */
24 public function prepare(array $events) {
25 if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
26 return;
27 }
28
29 $responses = $responseIDs = array();
30 foreach ($events as $event) {
31 $responseIDs[] = $event->objectID;
32 }
33
34 // fetch responses
35 $responseList = new CommentResponseList();
36 $responseList->setObjectIDs($responseIDs);
37 $responseList->readObjects();
38 $responses = $responseList->getObjects();
39
40 // fetch comments
41 $commentIDs = $comments = array();
42 foreach ($responses as $response) {
43 $commentIDs[] = $response->commentID;
44 }
45 if (!empty($commentIDs)) {
46 $commentList = new CommentList();
47 $commentList->setObjectIDs($commentIDs);
48 $commentList->readObjects();
49 $comments = $commentList->getObjects();
50 }
51
52 // fetch users
53 $userIDs = $users = array();
54 foreach ($comments as $comment) {
55 $userIDs[] = $comment->objectID;
56 $userIDs[] = $comment->userID;
57 }
58 if (!empty($userIDs)) {
59 $userList = new UserProfileList();
60 $userList->setObjectIDs($userIDs);
61 $userList->readObjects();
62 $users = $userList->getObjects();
63 }
64
65 // set message
66 foreach ($events as $event) {
67 if (isset($responses[$event->objectID])) {
68 $response = $responses[$event->objectID];
69 $comment = $comments[$response->commentID];
70 if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) {
71 if (!$users[$comment->objectID]->isProtected()) {
72 $event->setIsAccessible();
73
74 // title
75 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', array(
76 'commentAuthor' => $users[$comment->userID],
77 'user' => $users[$comment->objectID]
78 ));
79 $event->setTitle($text);
80
81 // description
82 $event->setDescription($response->getExcerpt());
83 }
84 continue;
85 }
86 }
87
88 $event->setIsOrphaned();
89 }
90 }
91 }