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\email\Email;
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 comments.
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 WoltLabSuite\Core\System\User\Notification\Event
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 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
61 if ($comment->userID) {
62 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
65 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
68 $messageID = '<com.woltlab.wcf.moderation.queue.notification/'.$comment->commentID.'@'.Email::getHost().'>';
71 'template' => 'email_notification_moderationQueueCommentResponse',
72 'application' => 'wcf',
73 'in-reply-to' => [$messageID],
75 '<com.woltlab.wcf.moderation.queue/'.$this->getModerationQueue()->queueID.'@'.Email::getHost().'>',
79 'moderationQueue' => $this->getModerationQueue(),
80 'commentAuthor' => $commentAuthor,
81 'languageItemPrefix' => $this->getLanguageItemPrefix()
89 public function getEventHash() {
90 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
96 public function getLink() {
97 return $this->getModerationQueue()->getLink() . '#comments';
103 public function getMessage() {
104 $authors = $this->getAuthors();
105 if (count($authors) > 1) {
106 if (isset($authors[0])) {
109 $count = count($authors);
111 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message.stacked', [
112 'authors' => array_values($authors),
114 'others' => $count - 1,
115 'moderationQueue' => $this->getModerationQueue()
119 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
120 if ($comment->userID) {
121 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
124 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
127 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
128 'author' => $this->author,
129 'commentAuthor' => $commentAuthor,
130 'moderationQueue' => $this->getModerationQueue()
135 * Returns the moderation queue object the responded to comment belongs to.
136 * Returns null if the active user has no access to the moderation queue.
138 * @return ViewableModerationQueue
140 public function getModerationQueue() {
141 if (!$this->moderationQueueLoaded) {
142 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
144 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
145 $this->moderationQueueLoaded = true;
148 return $this->moderationQueue;
152 * Returns the language item prefix for the notification texts.
156 public function getLanguageItemPrefix() {
157 if ($this->languageItemPrefix === null) {
158 /** @var IModerationQueueReportHandler $moderationHandler */
159 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
160 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
163 return $this->languageItemPrefix;
169 public function getTitle() {
170 $count = count($this->getAuthors());
172 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
174 'timesTriggered' => $this->notification->timesTriggered
178 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
184 protected function prepare() {
185 CommentRuntimeCache::getInstance()->cacheObjectID($this->userNotificationObject->commentID);
186 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);