81cf038969082914bdec67d188b3bcbd31d2a9b7
[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-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
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 $responses = $responseIDs = array();
26
27 if (WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
28 foreach ($events as $event) {
29 $responseIDs[] = $event->objectID;
30 }
31
32 // fetch responses
33 $responseList = new CommentResponseList();
34 $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($responseIDs));
35 $responseList->readObjects();
36 $responses = $responseList->getObjects();
37
38 // fetch comments
39 $commentIDs = $comments = array();
40 foreach ($responses as $response) {
41 $commentIDs[] = $response->commentID;
42 }
43 if (!empty($commentIDs)) {
44 $commentList = new CommentList();
45 $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
46 $commentList->readObjects();
47 $comments = $commentList->getObjects();
48 }
49
50 // fetch users
51 $userIDs = $users = array();
52 foreach ($comments as $comment) {
53 $userIDs[] = $comment->objectID;
54 $userIDs[] = $comment->userID;
55 }
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();
61 }
62 }
63
64 // set message
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();
71
72 // title
73 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', array(
74 'commentAuthor' => $users[$comment->userID],
75 'user' => $users[$comment->objectID]
76 ));
77 $event->setTitle($text);
78
79 // description
80 $event->setDescription($response->getExcerpt());
81 continue;
82 }
83 }
84
85 $event->setIsOrphaned();
86 }
87 }
88 }