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\cache\runtime\CommentRuntimeCache;
7 use wcf\system\cache\runtime\UserProfileRuntimeCache;
8 use wcf\system\email\Email;
9 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
10 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
14 * User notification event for moderation queue comments.
16 * @author Matthias Schmidt
17 * @copyright 2001-2016 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\System\User\Notification\Event
22 * @method CommentResponseUserNotificationObject getUserNotificationObject()
24 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent {
26 * language item prefix for the notification texts
29 protected $languageItemPrefix = null;
32 * moderation queue object the notifications (indirectly) belong to
33 * @var ViewableModerationQueue
35 protected $moderationQueue = null;
38 * true if the moderation queue is already loaded
41 protected $moderationQueueLoaded = false;
46 protected $stackable = true;
51 public function checkAccess() {
52 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
56 return $this->getModerationQueue()->canEdit();
62 public function getEmailMessage($notificationType = 'instant') {
63 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
64 if ($comment->userID) {
65 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
68 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
71 $messageID = '<com.woltlab.wcf.moderation.queue.notification/'.$comment->commentID.'@'.Email::getHost().'>';
74 'template' => 'email_notification_moderationQueueCommentResponse',
75 'application' => 'wcf',
76 'in-reply-to' => [$messageID],
78 '<com.woltlab.wcf.moderation.queue/'.$this->getModerationQueue()->queueID.'@'.Email::getHost().'>',
82 'moderationQueue' => $this->getModerationQueue(),
83 'commentAuthor' => $commentAuthor,
84 'languageItemPrefix' => $this->getLanguageItemPrefix()
92 public function getEventHash() {
93 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
99 public function getLink() {
100 return $this->getModerationQueue()->getLink() . '#comments';
106 public function getMessage() {
107 $authors = $this->getAuthors();
108 if (count($authors) > 1) {
109 if (isset($authors[0])) {
112 $count = count($authors);
114 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message.stacked', [
115 'authors' => array_values($authors),
117 'others' => $count - 1,
118 'moderationQueue' => $this->getModerationQueue()
122 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
123 if ($comment->userID) {
124 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
127 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
130 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
131 'author' => $this->author,
132 'commentAuthor' => $commentAuthor,
133 'moderationQueue' => $this->getModerationQueue()
138 * Returns the moderation queue object the responded to comment belongs to.
139 * Returns null if the active user has no access to the moderation queue.
141 * @return ViewableModerationQueue
143 public function getModerationQueue() {
144 if (!$this->moderationQueueLoaded) {
145 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
147 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
148 $this->moderationQueueLoaded = true;
151 return $this->moderationQueue;
155 * Returns the language item prefix for the notification texts.
159 public function getLanguageItemPrefix() {
160 if ($this->languageItemPrefix === null) {
161 /** @var IModerationQueueReportHandler $moderationHandler */
162 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
163 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
166 return $this->languageItemPrefix;
172 public function getTitle() {
173 $count = count($this->getAuthors());
175 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
177 'timesTriggered' => $this->notification->timesTriggered
181 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
187 protected function prepare() {
188 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
189 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);