2 namespace wcf\system\user\notification\event;
3 use wcf\data\moderation\queue\ViewableModerationQueue;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\CommentRuntimeCache;
7 use wcf\system\cache\runtime\UserProfileRuntimeCache;
8 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
12 * User notification event for moderation queue commments.
14 * @author Matthias Schmidt
15 * @copyright 2001-2016 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package com.woltlab.wcf
18 * @subpackage system.user.notification.event
19 * @category Community Framework
22 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
24 * language item prefix for the notification texts
27 protected $languageItemPrefix = null;
30 * moderation queue object the notifications (indirectly) belong to
31 * @var ViewableModerationQueue
33 protected $moderationQueue = null;
36 * true if the moderation queue is already loaded
39 protected $moderationQueueLoaded = false;
44 protected $stackable = true;
49 public function checkAccess() {
50 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
54 return $this->getModerationQueue()->canEdit();
60 public function getEmailMessage($notificationType = 'instant') {
61 $authors = $this->getAuthors();
62 if (count($authors) > 1) {
63 if (isset($authors[0])) {
66 $count = count($authors);
68 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail.stacked', [
69 'author' => $this->author,
70 'authors' => array_values($authors),
72 'notificationType' => $notificationType,
73 'others' => $count - 1,
74 'moderationQueue' => $this->getModerationQueue(),
75 'response' => $this->userNotificationObject
79 $comment = CommentRuntimeCache::getInstance()->getComment($this->userNotificationObject->commentID);
80 if ($comment->userID) {
81 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
84 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
87 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail', [
88 'author' => $this->author,
89 'commentAuthor' => $commentAuthor,
90 'moderationQueue' => $this->getModerationQueue(),
91 'notificationType' => $notificationType,
92 'response' => $this->userNotificationObject
99 public function getEventHash() {
100 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
106 public function getLink() {
107 return $this->getModerationQueue()->getLink() . '#comments';
113 public function getMessage() {
114 $authors = $this->getAuthors();
115 if (count($authors) > 1) {
116 if (isset($authors[0])) {
119 $count = count($authors);
121 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message.stacked', [
122 'authors' => array_values($authors),
124 'others' => $count - 1,
125 'moderationQueue' => $this->getModerationQueue()
129 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
130 if ($comment->userID) {
131 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
134 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
137 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
138 'author' => $this->author,
139 'commentAuthor' => $commentAuthor,
140 'moderationQueue' => $this->getModerationQueue()
145 * Returns the moderation queue object the responded to comment belongs to.
146 * Returns null if the active user has no access to the moderation queue.
148 * @return ViewableModerationQueue
150 public function getModerationQueue() {
151 if (!$this->moderationQueueLoaded) {
152 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
154 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
155 $this->moderationQueueLoaded = true;
158 return $this->moderationQueue;
162 * Returns the language item prefix for the notification texts.
166 public function getLanguageItemPrefix() {
167 if ($this->languageItemPrefix === null) {
168 /** @var IModerationQueueReportHandler $moderationHandler */
169 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
170 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
173 return $this->languageItemPrefix;
179 public function getTitle() {
180 $count = count($this->getAuthors());
182 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
184 'timesTriggered' => $this->notification->timesTriggered
188 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
194 protected function prepare() {
195 CommentRuntimeCache::getInstance()->cacheObjectID($this->userNotificationObject->commentID);
196 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);