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\UserProfileCache;
6 use wcf\system\SingletonFactory;
10 * User activity event implementation for profile comment responses.
13 * @copyright 2001-2015 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.user.activity.event
17 * @category Community Framework
19 class ProfileCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
21 * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare()
23 public function prepare(array $events) {
24 if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
28 $responses = $responseIDs = array();
29 foreach ($events as $event) {
30 $responseIDs[] = $event->objectID;
34 $responseList = new CommentResponseList();
35 $responseList->setObjectIDs($responseIDs);
36 $responseList->readObjects();
37 $responses = $responseList->getObjects();
40 $commentIDs = $comments = array();
41 foreach ($responses as $response) {
42 $commentIDs[] = $response->commentID;
44 if (!empty($commentIDs)) {
45 $commentList = new CommentList();
46 $commentList->setObjectIDs($commentIDs);
47 $commentList->readObjects();
48 $comments = $commentList->getObjects();
52 $userIDs = $users = array();
53 foreach ($comments as $comment) {
54 $userIDs[] = $comment->objectID;
55 $userIDs[] = $comment->userID;
57 if (!empty($userIDs)) {
58 $users = UserProfileCache::getInstance()->getUserProfiles($userIDs);
62 foreach ($events as $event) {
63 if (isset($responses[$event->objectID])) {
64 $response = $responses[$event->objectID];
65 $comment = $comments[$response->commentID];
66 if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) {
67 if (!$users[$comment->objectID]->isProtected()) {
68 $event->setIsAccessible();
71 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', array(
72 'commentAuthor' => $users[$comment->userID],
73 'user' => $users[$comment->objectID]
75 $event->setTitle($text);
78 $event->setDescription($response->getExcerpt());
84 $event->setIsOrphaned();