2 namespace wcf\system\user\notification\event;
3 use wcf\data\user\User;
4 use wcf\data\moderation\queue\ViewableModerationQueue;
5 use wcf\data\object\type\ObjectTypeCache;
6 use wcf\system\comment\CommentDataHandler;
7 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
11 * User notification event for moderation queue commments.
13 * @author Matthias Schmidt
14 * @copyright 2001-2016 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage system.user.notification.event
18 * @category Community Framework
21 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
23 * language item prefix for the notification texts
26 protected $languageItemPrefix = null;
29 * moderation queue object the notifications (indirectly) belong to
30 * @var ViewableModerationQueue
32 protected $moderationQueue = null;
35 * true if the moderation queue is already loaded
38 protected $moderationQueueLoaded = false;
43 protected $stackable = true;
48 public function checkAccess() {
49 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
53 return $this->getModerationQueue()->canEdit();
59 public function getEmailMessage($notificationType = 'instant') {
60 $authors = $this->getAuthors();
61 if (count($authors) > 1) {
62 if (isset($authors[0])) {
65 $count = count($authors);
67 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail.stacked', [
68 'author' => $this->author,
69 'authors' => array_values($authors),
71 'notificationType' => $notificationType,
72 'others' => $count - 1,
73 'moderationQueue' => $this->getModerationQueue(),
74 'response' => $this->userNotificationObject
78 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
79 if ($comment->userID) {
80 $commentAuthor = CommentDataHandler::getInstance()->getUser($comment->userID);
83 $commentAuthor = new User(null, [
84 'username' => $comment->username
88 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail', [
89 'author' => $this->author,
90 'commentAuthor' => $commentAuthor,
91 'moderationQueue' => $this->getModerationQueue(),
92 'notificationType' => $notificationType,
93 'response' => $this->userNotificationObject
100 public function getEventHash() {
101 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
107 public function getLink() {
108 return $this->getModerationQueue()->getLink() . '#comments';
114 public function getMessage() {
115 $authors = $this->getAuthors();
116 if (count($authors) > 1) {
117 if (isset($authors[0])) {
120 $count = count($authors);
122 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message.stacked', [
123 'authors' => array_values($authors),
125 'others' => $count - 1,
126 'moderationQueue' => $this->getModerationQueue()
130 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
131 if ($comment->userID) {
132 $commentAuthor = CommentDataHandler::getInstance()->getUser($comment->userID);
135 $commentAuthor = new User(null, [
136 'username' => $comment->username
140 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
141 'author' => $this->author,
142 'commentAuthor' => $commentAuthor,
143 'moderationQueue' => $this->getModerationQueue()
148 * Returns the moderation queue object the responded to comment belongs to.
149 * Returns null if the active user has no access to the moderation queue.
151 * @return ViewableModerationQueue
153 public function getModerationQueue() {
154 if (!$this->moderationQueueLoaded) {
155 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
157 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
158 $this->moderationQueueLoaded = true;
161 return $this->moderationQueue;
165 * Returns the language item prefix for the notification texts.
169 public function getLanguageItemPrefix() {
170 if ($this->languageItemPrefix === null) {
171 /** @var IModerationQueueReportHandler $moderationHandler */
172 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
173 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
176 return $this->languageItemPrefix;
182 public function getTitle() {
183 $count = count($this->getAuthors());
185 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
187 'timesTriggered' => $this->notification->timesTriggered
191 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
197 protected function prepare() {
198 CommentDataHandler::getInstance()->cacheCommentID($this->userNotificationObject->commentID);
199 CommentDataHandler::getInstance()->cacheUserID($this->additionalData['userID']);