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\comment\CommentHandler;
9 use wcf\system\email\Email;
10 use wcf\system\moderation\queue\report\IModerationQueueReportHandler;
11 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
15 * User notification event for moderation queue comments.
17 * @author Matthias Schmidt
18 * @copyright 2001-2019 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\System\User\Notification\Event
23 * @method CommentResponseUserNotificationObject getUserNotificationObject()
25 class ModerationQueueCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
26 use TTestableCommentResponseUserNotificationEvent;
27 use TTestableModerationQueueUserNotificationEvent;
30 * language item prefix for the notification texts
33 protected $languageItemPrefix = null;
36 * moderation queue object the notifications (indirectly) belong to
37 * @var ViewableModerationQueue
39 protected $moderationQueue = null;
42 * true if the moderation queue is already loaded
45 protected $moderationQueueLoaded = false;
50 protected $stackable = true;
55 public function checkAccess() {
56 if (!WCF::getSession()->getPermission('mod.general.canUseModeration') || $this->getModerationQueue() === null) {
60 return $this->getModerationQueue()->canEdit();
66 public function getEmailMessage($notificationType = 'instant') {
67 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
68 if ($comment->userID) {
69 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
72 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
75 $messageID = '<com.woltlab.wcf.moderation.queue.notification/'.$comment->commentID.'@'.Email::getHost().'>';
78 'template' => 'email_notification_moderationQueueCommentResponse',
79 'application' => 'wcf',
80 'in-reply-to' => [$messageID],
82 '<com.woltlab.wcf.moderation.queue/'.$this->getModerationQueue()->queueID.'@'.Email::getHost().'>',
86 'moderationQueue' => $this->getModerationQueue(),
87 'commentAuthor' => $commentAuthor,
88 'languageItemPrefix' => $this->getLanguageItemPrefix()
96 public function getEventHash() {
97 return sha1($this->eventID . '-' . $this->getModerationQueue()->queueID);
103 public function getLink() {
104 return $this->getModerationQueue()->getLink() . '#comment' . $this->getUserNotificationObject()->commentID;
110 public function getMessage() {
111 $authors = $this->getAuthors();
112 if (count($authors) > 1) {
113 if (isset($authors[0])) {
116 $count = count($authors);
118 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message.stacked', [
119 'authors' => array_values($authors),
120 'commentID' => $this->getUserNotificationObject()->commentID,
122 'others' => $count - 1,
123 'moderationQueue' => $this->getModerationQueue()
127 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->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 'commentID' => $this->getUserNotificationObject()->commentID,
139 'responseID' => $this->getUserNotificationObject()->responseID,
140 'moderationQueue' => $this->getModerationQueue()
145 * Returns the moderation queue object the responded to comment belongs to.
146 * Returns null if the active user has no access to the moderation queue.
148 * @return ViewableModerationQueue
150 public function getModerationQueue() {
151 if (!$this->moderationQueueLoaded) {
152 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
154 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
155 $this->moderationQueueLoaded = true;
158 return $this->moderationQueue;
162 * Returns the language item prefix for the notification texts.
166 public function getLanguageItemPrefix() {
167 if ($this->languageItemPrefix === null) {
168 /** @var IModerationQueueReportHandler $moderationHandler */
169 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
170 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
173 return $this->languageItemPrefix;
179 public function getTitle() {
180 $count = count($this->getAuthors());
182 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
184 'timesTriggered' => $this->notification->timesTriggered
188 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
194 protected function prepare() {
195 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
196 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);
203 public static function canBeTriggeredByGuests() {
211 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
213 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
214 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue')