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\notification\UserNotification;
7 use wcf\data\user\UserProfile;
8 use wcf\system\comment\CommentHandler;
9 use wcf\system\email\Email;
10 use wcf\system\moderation\queue\IModerationQueueHandler;
11 use wcf\system\user\notification\object\CommentUserNotificationObject;
12 use wcf\system\user\notification\object\IUserNotificationObject;
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 CommentUserNotificationObject getUserNotificationObject()
26 class ModerationQueueCommentUserNotificationEvent extends AbstractUserNotificationEvent implements ITestableUserNotificationEvent {
27 use TTestableCommentUserNotificationEvent;
28 use TTestableModerationQueueUserNotificationEvent;
31 * language item prefix for the notification texts
34 protected $languageItemPrefix = '';
37 * moderation queue object the notifications (indirectly) belong to
38 * @var ViewableModerationQueue
40 protected $moderationQueue = null;
45 protected $stackable = true;
50 public function checkAccess() {
51 if ($this->moderationQueue === null || !WCF::getSession()->getPermission('mod.general.canUseModeration')) {
55 return $this->moderationQueue->canEdit();
61 public function getEmailMessage($notificationType = 'instant') {
63 'message-id' => 'com.woltlab.wcf.moderation.queue.notification/'.$this->getUserNotificationObject()->commentID,
64 'template' => 'email_notification_moderationQueueComment',
65 'application' => 'wcf',
67 '<com.woltlab.wcf.moderation.queue/'.$this->moderationQueue->queueID.'@'.Email::getHost().'>'
70 'moderationQueue' => $this->moderationQueue,
71 'languageItemPrefix' => $this->languageItemPrefix
79 public function getEventHash() {
80 return sha1($this->eventID . '-' . $this->moderationQueue->queueID);
86 public function getLink() {
87 return $this->moderationQueue->getLink() . '#comments';
93 public function getMessage() {
94 $authors = $this->getAuthors();
95 if (count($authors) > 1) {
96 if (isset($authors[0])) {
99 $count = count($authors);
101 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.message.stacked', [
102 'author' => $this->author,
103 'authors' => array_values($authors),
105 'others' => $count - 1,
106 'moderationQueue' => $this->moderationQueue
110 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.message', [
111 'author' => $this->author,
112 'commentID' => $this->getUserNotificationObject()->commentID,
113 'moderationQueue' => $this->moderationQueue
120 public function getTitle() {
121 $count = count($this->getAuthors());
123 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.title.stacked', [
125 'timesTriggered' => $this->notification->timesTriggered
129 return $this->getLanguage()->get($this->languageItemPrefix.'.comment.title');
135 public function setObject(UserNotification $notification, IUserNotificationObject $object, UserProfile $author, array $additionalData = []) {
136 parent::setObject($notification, $object, $author, $additionalData);
138 // if the active user has no access, $this->moderationQueue is null
139 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($this->getUserNotificationObject()->objectID);
141 if ($this->moderationQueue) {
142 /** @var IModerationQueueHandler $moderationHandler */
143 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->moderationQueue->objectTypeID)->getProcessor();
144 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
152 public static function canBeTriggeredByGuests() {
160 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
162 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
163 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue')