2 namespace wcf\system\user\notification\event;
3 use wcf\data\moderation\queue\ViewableModerationQueue;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\system\comment\CommentDataHandler;
6 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
10 * User notification event for moderation queue commments.
12 * @author Matthias Schmidt
13 * @copyright 2001-2016 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.user.notification.event
17 * @category Community Framework
20 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
22 * language item prefix for the notification texts
25 protected $languageItemPrefix = null;
28 * moderation queue object the notifications (indirectly) belong to
29 * @var ViewableModerationQueue
31 protected $moderationQueue = null;
34 * true if the moderation queue is already loaded
37 protected $moderationQueueLoaded = false;
42 protected $stackable = true;
47 public function checkAccess() {
48 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
52 return $this->getModerationQueue()->canEdit();
58 public function getEmailMessage($notificationType = 'instant') {
59 $authors = $this->getAuthors();
60 if (count($authors) > 1) {
61 if (isset($authors[0])) {
64 $count = count($authors);
66 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail.stacked', [
67 'author' => $this->author,
68 'authors' => array_values($authors),
70 'notificationType' => $notificationType,
71 'others' => $count - 1,
72 'moderationQueue' => $this->getModerationQueue(),
73 'response' => $this->userNotificationObject
77 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
78 if ($comment->userID) {
79 $commentAuthor = CommentDataHandler::getInstance()->getUser($comment->userID);
82 $commentAuthor = new User(null, [
83 'username' => $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 = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
130 if ($comment->userID) {
131 $commentAuthor = CommentDataHandler::getInstance()->getUser($comment->userID);
134 $commentAuthor = new User(null, [
135 'username' => $comment->username
139 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
140 'author' => $this->author,
141 'commentAuthor' => $commentAuthor,
142 'moderationQueue' => $this->getModerationQueue()
147 * Returns the moderation queue object the responded to comment belongs to.
148 * Returns null if the active user has no access to the moderation queue.
150 * @return ViewableModerationQueue
152 public function getModerationQueue() {
153 if (!$this->moderationQueueLoaded) {
154 $comment = CommentDataHandler::getInstance()->getComment($this->userNotificationObject->commentID);
156 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
157 $this->moderationQueueLoaded = true;
160 return $this->moderationQueue;
164 * Returns the language item prefix for the notification texts.
168 public function getLanguageItemPrefix() {
169 if ($this->languageItemPrefix === null) {
170 /** @var IModerationQueueReportHandler $moderationHandler */
171 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
172 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
175 return $this->languageItemPrefix;
181 public function getTitle() {
182 $count = count($this->getAuthors());
184 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
186 'timesTriggered' => $this->notification->timesTriggered
190 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
196 protected function prepare() {
197 CommentDataHandler::getInstance()->cacheCommentID($this->userNotificationObject->commentID);
198 CommentDataHandler::getInstance()->cacheUserID($this->additionalData['userID']);