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