2 namespace wcf\system\user\activity\event;
3 use wcf\data\comment\response\CommentResponseList;
4 use wcf\data\comment\CommentList;
5 use wcf\system\cache\runtime\UserProfileRuntimeCache;
6 use wcf\system\SingletonFactory;
10 * User activity event implementation for profile comment responses.
13 * @copyright 2001-2016 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\User\Activity\Event
17 class ProfileCommentResponseUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
21 public function prepare(array $events) {
22 if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
27 foreach ($events as $event) {
28 $responseIDs[] = $event->objectID;
32 $responseList = new CommentResponseList();
33 $responseList->setObjectIDs($responseIDs);
34 $responseList->readObjects();
35 $responses = $responseList->getObjects();
38 $commentIDs = $comments = [];
39 foreach ($responses as $response) {
40 $commentIDs[] = $response->commentID;
42 if (!empty($commentIDs)) {
43 $commentList = new CommentList();
44 $commentList->setObjectIDs($commentIDs);
45 $commentList->readObjects();
46 $comments = $commentList->getObjects();
50 $userIDs = $users = [];
51 foreach ($comments as $comment) {
52 $userIDs[] = $comment->objectID;
53 $userIDs[] = $comment->userID;
55 if (!empty($userIDs)) {
56 $users = UserProfileRuntimeCache::getInstance()->getObjects($userIDs);
60 foreach ($events as $event) {
61 if (isset($responses[$event->objectID])) {
62 $response = $responses[$event->objectID];
63 $comment = $comments[$response->commentID];
64 if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) {
65 if (!$users[$comment->objectID]->isProtected()) {
66 $event->setIsAccessible();
69 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', [
70 'commentAuthor' => $users[$comment->userID],
71 'user' => $users[$comment->objectID]
73 $event->setTitle($text);
76 $event->setDescription($response->getExcerpt());
82 $event->setIsOrphaned();