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\User;
6 use wcf\data\user\UserProfile;
7 use wcf\system\cache\runtime\CommentRuntimeCache;
8 use wcf\system\cache\runtime\UserProfileRuntimeCache;
9 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
13 * User notification event for moderation queue commments.
15 * @author Matthias Schmidt
16 * @copyright 2001-2016 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package com.woltlab.wcf
19 * @subpackage system.user.notification.event
20 * @category Community Framework
23 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
25 * language item prefix for the notification texts
28 protected $languageItemPrefix = null;
31 * moderation queue object the notifications (indirectly) belong to
32 * @var ViewableModerationQueue
34 protected $moderationQueue = null;
37 * true if the moderation queue is already loaded
40 protected $moderationQueueLoaded = false;
45 protected $stackable = true;
50 public function checkAccess() {
51 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
55 return $this->getModerationQueue()->canEdit();
61 public function getEmailMessage($notificationType = 'instant') {
62 $authors = $this->getAuthors();
63 if (count($authors) > 1) {
64 if (isset($authors[0])) {
67 $count = count($authors);
69 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail.stacked', [
70 'author' => $this->author,
71 'authors' => array_values($authors),
73 'notificationType' => $notificationType,
74 'others' => $count - 1,
75 'moderationQueue' => $this->getModerationQueue(),
76 'response' => $this->userNotificationObject
80 $comment = CommentRuntimeCache::getInstance()->getComment($this->userNotificationObject->commentID);
81 if ($comment->userID) {
82 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
85 $commentAuthor = new UserProfile(new User(null, [
86 'username' => $comment->username
90 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail', [
91 'author' => $this->author,
92 'commentAuthor' => $commentAuthor,
93 'moderationQueue' => $this->getModerationQueue(),
94 'notificationType' => $notificationType,
95 'response' => $this->userNotificationObject
102 public function getEventHash() {
103 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
109 public function getLink() {
110 return $this->getModerationQueue()->getLink() . '#comments';
116 public function getMessage() {
117 $authors = $this->getAuthors();
118 if (count($authors) > 1) {
119 if (isset($authors[0])) {
122 $count = count($authors);
124 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message.stacked', [
125 'authors' => array_values($authors),
127 'others' => $count - 1,
128 'moderationQueue' => $this->getModerationQueue()
132 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
133 if ($comment->userID) {
134 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
137 $commentAuthor = new UserProfile(new User(null, [
138 'username' => $comment->username
142 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
143 'author' => $this->author,
144 'commentAuthor' => $commentAuthor,
145 'moderationQueue' => $this->getModerationQueue()
150 * Returns the moderation queue object the responded to comment belongs to.
151 * Returns null if the active user has no access to the moderation queue.
153 * @return ViewableModerationQueue
155 public function getModerationQueue() {
156 if (!$this->moderationQueueLoaded) {
157 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
159 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
160 $this->moderationQueueLoaded = true;
163 return $this->moderationQueue;
167 * Returns the language item prefix for the notification texts.
171 public function getLanguageItemPrefix() {
172 if ($this->languageItemPrefix === null) {
173 /** @var IModerationQueueReportHandler $moderationHandler */
174 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
175 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
178 return $this->languageItemPrefix;
184 public function getTitle() {
185 $count = count($this->getAuthors());
187 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
189 'timesTriggered' => $this->notification->timesTriggered
193 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
199 protected function prepare() {
200 CommentRuntimeCache::getInstance()->cacheObjectID($this->userNotificationObject->commentID);
201 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);