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\moderation\queue\report\IModerationQueueReportHandler;
12 * User notification event for moderation queue comments.
14 * @author Matthias Schmidt
15 * @copyright 2001-2016 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\User\Notification\Event
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 = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
78 if ($comment->userID) {
79 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
82 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
85 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail', [
86 'author' => $this->author,
87 'commentAuthor' => $commentAuthor,
88 'moderationQueue' => $this->getModerationQueue(),
89 'notificationType' => $notificationType,
90 'response' => $this->userNotificationObject
97 public function getEventHash() {
98 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
104 public function getLink() {
105 return $this->getModerationQueue()->getLink() . '#comments';
111 public function getMessage() {
112 $authors = $this->getAuthors();
113 if (count($authors) > 1) {
114 if (isset($authors[0])) {
117 $count = count($authors);
119 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message.stacked', [
120 'authors' => array_values($authors),
122 'others' => $count - 1,
123 'moderationQueue' => $this->getModerationQueue()
127 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
128 if ($comment->userID) {
129 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
132 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
135 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
136 'author' => $this->author,
137 'commentAuthor' => $commentAuthor,
138 'moderationQueue' => $this->getModerationQueue()
143 * Returns the moderation queue object the responded to comment belongs to.
144 * Returns null if the active user has no access to the moderation queue.
146 * @return ViewableModerationQueue
148 public function getModerationQueue() {
149 if (!$this->moderationQueueLoaded) {
150 $comment = CommentRuntimeCache::getInstance()->getObject($this->userNotificationObject->commentID);
152 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
153 $this->moderationQueueLoaded = true;
156 return $this->moderationQueue;
160 * Returns the language item prefix for the notification texts.
164 public function getLanguageItemPrefix() {
165 if ($this->languageItemPrefix === null) {
166 /** @var IModerationQueueReportHandler $moderationHandler */
167 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
168 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
171 return $this->languageItemPrefix;
177 public function getTitle() {
178 $count = count($this->getAuthors());
180 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
182 'timesTriggered' => $this->notification->timesTriggered
186 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
192 protected function prepare() {
193 CommentRuntimeCache::getInstance()->cacheObjectID($this->userNotificationObject->commentID);
194 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);