2 declare(strict_types=1);
3 namespace wcf\system\user\notification\event;
4 use wcf\data\moderation\queue\ViewableModerationQueue;
5 use wcf\data\object\type\ObjectTypeCache;
6 use wcf\data\user\UserProfile;
7 use wcf\system\cache\runtime\CommentRuntimeCache;
8 use wcf\system\cache\runtime\UserProfileRuntimeCache;
9 use wcf\system\comment\CommentHandler;
10 use wcf\system\email\Email;
11 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
12 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
16 * User notification event for moderation queue comments.
18 * @author Matthias Schmidt
19 * @copyright 2001-2018 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package WoltLabSuite\Core\System\User\Notification\Event
24 * @method CommentResponseUserNotificationObject getUserNotificationObject()
26 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
27 use TTestableCommentResponseUserNotificationEvent;
28 use TTestableModerationQueueUserNotificationEvent;
31 * language item prefix for the notification texts
34 protected $languageItemPrefix = null;
37 * moderation queue object the notifications (indirectly) belong to
38 * @var ViewableModerationQueue
40 protected $moderationQueue = null;
43 * true if the moderation queue is already loaded
46 protected $moderationQueueLoaded = false;
51 protected $stackable = true;
56 public function checkAccess() {
57 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
61 return $this->getModerationQueue()->canEdit();
67 public function getEmailMessage($notificationType = 'instant') {
68 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
69 if ($comment->userID) {
70 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
73 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
76 $messageID = '<com.woltlab.wcf.moderation.queue.notification/'.$comment->commentID.'@'.Email::getHost().'>';
79 'template' => 'email_notification_moderationQueueCommentResponse',
80 'application' => 'wcf',
81 'in-reply-to' => [$messageID],
83 '<com.woltlab.wcf.moderation.queue/'.$this->getModerationQueue()->queueID.'@'.Email::getHost().'>',
87 'moderationQueue' => $this->getModerationQueue(),
88 'commentAuthor' => $commentAuthor,
89 'languageItemPrefix' => $this->getLanguageItemPrefix()
97 public function getEventHash() {
98 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
104 public function getLink() {
105 return $this->getModerationQueue()->getLink() . '#comment' . $this->getUserNotificationObject()->commentID;
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),
121 'commentID' => $this->getUserNotificationObject()->commentID,
123 'others' => $count - 1,
124 'moderationQueue' => $this->getModerationQueue()
128 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
129 if ($comment->userID) {
130 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
133 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
136 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
137 'author' => $this->author,
138 'commentAuthor' => $commentAuthor,
139 'commentID' => $this->getUserNotificationObject()->commentID,
140 'responseID' => $this->getUserNotificationObject()->responseID,
141 'moderationQueue' => $this->getModerationQueue()
146 * Returns the moderation queue object the responded to comment belongs to.
147 * Returns null if the active user has no access to the moderation queue.
149 * @return ViewableModerationQueue
151 public function getModerationQueue() {
152 if (!$this->moderationQueueLoaded) {
153 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
155 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
156 $this->moderationQueueLoaded = true;
159 return $this->moderationQueue;
163 * Returns the language item prefix for the notification texts.
167 public function getLanguageItemPrefix() {
168 if ($this->languageItemPrefix === null) {
169 /** @var IModerationQueueReportHandler $moderationHandler */
170 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
171 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
174 return $this->languageItemPrefix;
180 public function getTitle() {
181 $count = count($this->getAuthors());
183 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
185 'timesTriggered' => $this->notification->timesTriggered
189 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
195 protected function prepare() {
196 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
197 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);
204 public static function canBeTriggeredByGuests() {
212 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
214 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
215 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue')