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;
11 * User activity event implementation for profile comment responses.
14 * @copyright 2001-2012 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf.comment
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 $responses = $responseIDs = array();
27 if (WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
28 foreach ($events as $event) {
29 $responseIDs[] = $event->objectID;
33 $responseList = new CommentResponseList();
34 $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($responseIDs));
35 $responseList->readObjects();
36 $responses = $responseList->getObjects();
39 $commentIDs = $comments = array();
40 foreach ($responses as $response) {
41 $commentIDs[] = $response->commentID;
43 if (!empty($commentIDs)) {
44 $commentList = new CommentList();
45 $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
46 $commentList->readObjects();
47 $comments = $commentList->getObjects();
51 $userIDs = $users = array();
52 foreach ($comments as $comment) {
53 $userIDs[] = $comment->objectID;
54 $userIDs[] = $comment->userID;
56 if (!empty($userIDs)) {
57 $userList = new UserProfileList();
58 $userList->getConditionBuilder()->add("user_table.userID IN (?)", array($userIDs));
59 $userList->readObjects();
60 $users = $userList->getObjects();
65 foreach ($events as $event) {
66 if (isset($responses[$event->objectID])) {
67 $response = $responses[$event->objectID];
68 $comment = $comments[$response->commentID];
69 if (isset($users[$comment->objectID]) && isset($users[$comment->userID]) && !$users[$comment->objectID]->isProtected()) {
70 $event->setIsAccessible();
73 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', array(
74 'commentAuthor' => $users[$comment->userID],
75 'user' => $users[$comment->objectID]
77 $event->setTitle($text);
80 $event->setDescription($response->getExcerpt());
85 $event->setIsOrphaned();