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-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 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() . '#comments';
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),
121 'others' => $count - 1,
122 'moderationQueue' => $this->getModerationQueue()
126 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
127 if ($comment->userID) {
128 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
131 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
134 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [
135 'author' => $this->author,
136 'commentAuthor' => $commentAuthor,
137 'moderationQueue' => $this->getModerationQueue()
142 * Returns the moderation queue object the responded to comment belongs to.
143 * Returns null if the active user has no access to the moderation queue.
145 * @return ViewableModerationQueue
147 public function getModerationQueue() {
148 if (!$this->moderationQueueLoaded) {
149 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
151 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($comment->objectID);
152 $this->moderationQueueLoaded = true;
155 return $this->moderationQueue;
159 * Returns the language item prefix for the notification texts.
163 public function getLanguageItemPrefix() {
164 if ($this->languageItemPrefix === null) {
165 /** @var IModerationQueueReportHandler $moderationHandler */
166 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->getModerationQueue()->objectTypeID)->getProcessor();
167 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
170 return $this->languageItemPrefix;
176 public function getTitle() {
177 $count = count($this->getAuthors());
179 return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.title.stacked', [
181 'timesTriggered' => $this->notification->timesTriggered
185 return $this->getLanguage()->get($this->getLanguageItemPrefix().'.commentResponse.title');
191 protected function prepare() {
192 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
193 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->additionalData['userID']);
200 public static function canBeTriggeredByGuests() {
208 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
210 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
211 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue')