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\notification\UserNotification;
6 use wcf\data\user\UserProfile;
7 use wcf\system\comment\CommentHandler;
8 use wcf\system\email\Email;
9 use wcf\system\moderation\queue\IModerationQueueHandler;
10 use wcf\system\user\notification\object\CommentUserNotificationObject;
11 use wcf\system\user\notification\object\IUserNotificationObject;
15 * User notification event for moderation queue comments.
17 * @author Matthias Schmidt
18 * @copyright 2001-2017 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 CommentUserNotificationObject getUserNotificationObject()
25 class ModerationQueueCommentUserNotificationEvent extends AbstractUserNotificationEvent implements ITestableUserNotificationEvent {
26 use TTestableCommentUserNotificationEvent;
27 use TTestableModerationQueueUserNotificationEvent;
30 * language item prefix for the notification texts
33 protected $languageItemPrefix = '';
36 * moderation queue object the notifications (indirectly) belong to
37 * @var ViewableModerationQueue
39 protected $moderationQueue = null;
44 protected $stackable = true;
49 public function checkAccess() {
50 if ($this->moderationQueue === null || !WCF::getSession()->getPermission('mod.general.canUseModeration')) {
54 return $this->moderationQueue->canEdit();
60 public function getEmailMessage($notificationType = 'instant') {
62 'message-id' => 'com.woltlab.wcf.moderation.queue.notification/'.$this->getUserNotificationObject()->commentID,
63 'template' => 'email_notification_moderationQueueComment',
64 'application' => 'wcf',
66 '<com.woltlab.wcf.moderation.queue/'.$this->moderationQueue->queueID.'@'.Email::getHost().'>'
69 'moderationQueue' => $this->moderationQueue,
70 'languageItemPrefix' => $this->languageItemPrefix
78 public function getEventHash() {
79 return sha1($this->eventID . '-' . $this->moderationQueue->queueID);
85 public function getLink() {
86 return $this->moderationQueue->getLink() . '#comments';
92 public function getMessage() {
93 $authors = $this->getAuthors();
94 if (count($authors) > 1) {
95 if (isset($authors[0])) {
98 $count = count($authors);
100 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.message.stacked', [
101 'author' => $this->author,
102 'authors' => array_values($authors),
104 'others' => $count - 1,
105 'moderationQueue' => $this->moderationQueue
109 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.message', [
110 'author' => $this->author,
111 'moderationQueue' => $this->moderationQueue
118 public function getTitle() {
119 $count = count($this->getAuthors());
121 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.title.stacked', [
123 'timesTriggered' => $this->notification->timesTriggered
127 return $this->getLanguage()->get($this->languageItemPrefix.'.comment.title');
133 public function setObject(UserNotification $notification, IUserNotificationObject $object, UserProfile $author, array $additionalData = []) {
134 parent::setObject($notification, $object, $author, $additionalData);
136 // if the active user has no access, $this->moderationQueue is null
137 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($this->getUserNotificationObject()->objectID);
139 if ($this->moderationQueue) {
140 /** @var IModerationQueueHandler $moderationHandler */
141 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->moderationQueue->objectTypeID)->getProcessor();
142 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
150 public static function canBeTriggeredByGuests() {
158 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
160 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
161 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue')