4d87272ca1d1bd1c71bbf38e418c3908d8c9a981
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\moderation\queue\ViewableModerationQueue;
6 use wcf\data\object\type\ObjectTypeCache;
7 use wcf\data\user\UserProfile;
8 use wcf\system\email\Email;
9 use wcf\system\moderation\queue\IModerationQueueHandler;
10 use wcf\system\request\LinkHandler;
11 use wcf\system\user\notification\object\ModerationQueueUserNotificationObject;
12 use wcf\system\WCF;
13
14 /**
15 * Notification event for new reports in the moderation queue.
16 *
17 * @author Olaf Braun
18 * @copyright 2001-2024 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @since 6.1
21 *
22 * @method ModerationQueueUserNotificationObject getUserNotificationObject()
23 */
24 final class ReportModerationQueueUserNotificationEvent extends AbstractUserNotificationEvent implements
25 ITestableUserNotificationEvent
26 {
27 use TTestableModerationQueueUserNotificationEvent;
28 use TTestableUserNotificationEvent;
29
30 private ViewableModerationQueue $viewableModerationQueue;
31 #[\Override]
32 public function getTitle(): string
33 {
34 return $this->getLanguage()->get('wcf.moderation.report.notification.title');
35 }
36
37 #[\Override]
38 public function getMessage()
39 {
40 return $this->getLanguage()->getDynamicVariable(
41 'wcf.moderation.report.notification.message',
42 [
43 'author' => $this->author,
44 'notification' => $this->notification,
45 'moderationQueue' => $this->getViewableModerationQueue(),
46 ]
47 );
48 }
49
50 #[\Override]
51 public function getEmailMessage($notificationType = 'instant')
52 {
53 return [
54 'message-id' => 'com.woltlab.wcf.moderation.queue.notification/'
55 . $this->getUserNotificationObject()->queueID,
56 'template' => 'email_notification_moderationQueueReport',
57 'application' => 'wcf',
58 'references' => [
59 '<com.woltlab.wcf.moderation.queue/'
60 . $this->getUserNotificationObject()->queueID . '@' . Email::getHost() . '>',
61 ],
62 'variables' => [
63 'author' => $this->author,
64 'notification' => $this->notification,
65 'moderationQueue' => $this->getViewableModerationQueue(),
66 ],
67 ];
68 }
69
70 #[\Override]
71 public function getLink(): string
72 {
73 return LinkHandler::getInstance()->getLink('ModerationReport', [
74 'id' => $this->getUserNotificationObject()->queueID,
75 ]);
76 }
77
78 #[\Override]
79 public function getEventHash()
80 {
81 return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->queueID);
82 }
83
84 #[\Override]
85 public function checkAccess()
86 {
87 $objectType = ObjectTypeCache::getInstance()->getObjectType($this->getUserNotificationObject()->objectTypeID);
88 $processor = $objectType->getProcessor();
89 \assert($processor instanceof IModerationQueueHandler);
90
91 return $processor->isAffectedUser(
92 $this->getUserNotificationObject()->getDecoratedObject(),
93 WCF::getUser()->userID
94 );
95 }
96
97 private function getViewableModerationQueue(): ViewableModerationQueue
98 {
99 if (!isset($this->viewableModerationQueue)) {
100 $this->viewableModerationQueue = ViewableModerationQueue::getViewableModerationQueue(
101 $this->getUserNotificationObject()->queueID
102 );
103 }
104 return $this->viewableModerationQueue;
105 }
106
107 #[\Override]
108 public static function canBeTriggeredByGuests()
109 {
110 return true;
111 }
112
113 #[\Override]
114 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
115 {
116 return [new ModerationQueueUserNotificationObject(self::getTestUserModerationQueueEntry($recipient, $author))];
117 }
118 }