3 namespace wcf\system\user\notification\event;
5 use wcf\data\moderation\queue\ViewableModerationQueue;
6 use wcf\data\object\type\ObjectTypeCache;
7 use wcf\data\user\UserProfile;
8 use wcf\system\cache\runtime\CommentRuntimeCache;
9 use wcf\system\cache\runtime\UserProfileRuntimeCache;
10 use wcf\system\comment\CommentHandler;
11 use wcf\system\email\Email;
12 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
13 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
17 * User notification event for moderation queue comments.
19 * @author Matthias Schmidt
20 * @copyright 2001-2019 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
24 * @method CommentResponseUserNotificationObject getUserNotificationObject()
26 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements
27 ITestableUserNotificationEvent
29 use TTestableCommentResponseUserNotificationEvent;
30 use TTestableModerationQueueUserNotificationEvent;
33 * language item prefix for the notification texts
36 protected $languageItemPrefix;
39 * moderation queue object the notifications (indirectly) belong to
40 * @var ViewableModerationQueue
42 protected $moderationQueue;
45 * true if the moderation queue is already loaded
48 protected $moderationQueueLoaded = false;
53 protected $stackable = true;
58 public function checkAccess()
60 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
64 return $this->getModerationQueue()->canEdit();
70 public function getEmailMessage($notificationType = 'instant')
72 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
73 if ($comment->userID) {
74 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
76 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
79 $messageID = '<com.woltlab.wcf.moderation.queue.notification/' . $comment->commentID . '@' . Email::getHost() . '>';
82 'template' => 'email_notification_moderationQueueCommentResponse',
83 'application' => 'wcf',
84 'in-reply-to' => [$messageID],
86 '<com.woltlab.wcf.moderation.queue/' . $this->getModerationQueue()->queueID . '@' . Email::getHost() . '>',
90 'moderationQueue' => $this->getModerationQueue(),
91 'commentAuthor' => $commentAuthor,
92 'languageItemPrefix' => $this->getLanguageItemPrefix(),
100 public function getEventHash()
102 return \sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
108 public function getLink(): string
110 return $this->getModerationQueue()->getLink() . '#comment' . $this->getUserNotificationObject()->commentID;
116 public function getMessage()
118 $authors = $this->getAuthors();
119 if (\count($authors) > 1) {
120 if (isset($authors[0])) {
123 $count = \count($authors);
125 return $this->getLanguage()->getDynamicVariable(
126 $this->getLanguageItemPrefix() . '.commentResponse.message.stacked',
128 'authors' => \array_values($authors),
129 'commentID' => $this->getUserNotificationObject()->commentID,
131 'others' => $count - 1,
132 'moderationQueue' => $this->getModerationQueue(),
137 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
138 if ($comment->userID) {
139 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
141 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
144 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix() . '.commentResponse.message', [
145 'author' => $this->author,
146 'commentAuthor' => $commentAuthor,
147 'commentID' => $this->getUserNotificationObject()->commentID,
148 'responseID' => $this->getUserNotificationObject()->responseID,
149 'moderationQueue' => $this->getModerationQueue(),
154 * Returns the moderation queue object the responded to comment belongs to.
155 * Returns null if the active user has no access to the moderation queue.
157 * @return ViewableModerationQueue
159 public function getModerationQueue()
161 if (!$this->moderationQueueLoaded) {
162 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
164 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
165 $this->moderationQueueLoaded = true;
168 return $this->moderationQueue;
172 * Returns the language item prefix for the notification texts.
176 public function getLanguageItemPrefix()
178 if ($this->languageItemPrefix === null) {
179 /** @var IModerationQueueReportHandler $moderationHandler */
180 $moderationHandler = ObjectTypeCache::getInstance()
181 ->getObjectType($this->getModerationQueue()->objectTypeID)
183 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
186 return $this->languageItemPrefix;
192 public function getTitle(): string
194 $count = \count($this->getAuthors());
196 return $this->getLanguage()->getDynamicVariable(
197 $this->getLanguageItemPrefix() . '.commentResponse.title.stacked',
200 'timesTriggered' => $this->notification->timesTriggered,
205 return $this->getLanguage()->get($this->getLanguageItemPrefix() . '.commentResponse.title');
211 protected function prepare()
213 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
214 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);
221 public static function canBeTriggeredByGuests()
230 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
233 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
234 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue'),