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\user\activity\event\IUserActivityEvent;
7 use wcf\system\SingletonFactory;
11 * User activity event implementation for profile comment responses.
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
20 class ProfileCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
22 * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare()
24 public function prepare(array $events) {
25 if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
29 $responses = $responseIDs = array();
30 foreach ($events as $event) {
31 $responseIDs[] = $event->objectID;
35 $responseList = new CommentResponseList();
36 $responseList->setObjectIDs($responseIDs);
37 $responseList->readObjects();
38 $responses = $responseList->getObjects();
41 $commentIDs = $comments = array();
42 foreach ($responses as $response) {
43 $commentIDs[] = $response->commentID;
45 if (!empty($commentIDs)) {
46 $commentList = new CommentList();
47 $commentList->setObjectIDs($commentIDs);
48 $commentList->readObjects();
49 $comments = $commentList->getObjects();
53 $userIDs = $users = array();
54 foreach ($comments as $comment) {
55 $userIDs[] = $comment->objectID;
56 $userIDs[] = $comment->userID;
58 if (!empty($userIDs)) {
59 $users = UserProfileCache::getInstance()->getUserProfiles($userIDs);
63 foreach ($events as $event) {
64 if (isset($responses[$event->objectID])) {
65 $response = $responses[$event->objectID];
66 $comment = $comments[$response->commentID];
67 if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) {
68 if (!$users[$comment->objectID]->isProtected()) {
69 $event->setIsAccessible();
72 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', array(
73 'commentAuthor' => $users[$comment->userID],
74 'user' => $users[$comment->objectID]
76 $event->setTitle($text);
79 $event->setDescription($response->getExcerpt());
85 $event->setIsOrphaned();