d207b4f45b624a46c3d20b9b1d804b8a129e9313
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\moderation\queue\ModerationQueue;
6 use wcf\data\moderation\queue\ViewableModerationQueue;
7 use wcf\data\object\type\ObjectTypeCache;
8 use wcf\data\user\notification\UserNotification;
9 use wcf\data\user\UserProfile;
10 use wcf\system\comment\CommentHandler;
11 use wcf\system\email\Email;
12 use wcf\system\moderation\queue\IModerationQueueHandler;
13 use wcf\system\user\notification\object\CommentUserNotificationObject;
14 use wcf\system\user\notification\object\IUserNotificationObject;
15 use wcf\system\WCF;
16
17 /**
18 * User notification event for moderation queue comments.
19 *
20 * @author Matthias Schmidt
21 * @copyright 2001-2019 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 * @since 3.0
24 *
25 * @method CommentUserNotificationObject getUserNotificationObject()
26 */
27 class ModerationQueueCommentUserNotificationEvent extends AbstractCommentUserNotificationEvent implements
28 ITestableUserNotificationEvent
29 {
30 use TTestableCommentUserNotificationEvent;
31 use TTestableModerationQueueUserNotificationEvent;
32
33 /**
34 * language item prefix for the notification texts
35 * @var string
36 */
37 protected $languageItemPrefix = '';
38
39 /**
40 * language item for the type name
41 */
42 protected string $typeName;
43
44 /**
45 * moderation queue object the notifications (indirectly) belong to
46 * @var ViewableModerationQueue
47 */
48 protected $moderationQueue;
49
50 /**
51 * @inheritDoc
52 */
53 public function checkAccess()
54 {
55 if (!WCF::getSession()->getPermission('mod.general.canUseModeration')) {
56 return false;
57 }
58
59 return $this->moderationQueue->canEdit();
60 }
61
62 /**
63 * @inheritDoc
64 */
65 public function getEmailMessage($notificationType = 'instant')
66 {
67 return [
68 'message-id' => 'com.woltlab.wcf.moderation.queue.notification/' . $this->getUserNotificationObject()->commentID,
69 'template' => 'email_notification_moderationQueueComment',
70 'application' => 'wcf',
71 'references' => [
72 '<com.woltlab.wcf.moderation.queue/' . $this->moderationQueue->queueID . '@' . Email::getHost() . '>',
73 ],
74 'variables' => [
75 'moderationQueue' => $this->moderationQueue,
76 'languageItemPrefix' => $this->languageItemPrefix,
77 ],
78 ];
79 }
80
81 /**
82 * @inheritDoc
83 */
84 public function getEventHash()
85 {
86 return \sha1($this->eventID . '-' . $this->moderationQueue->queueID);
87 }
88
89 /**
90 * @inheritDoc
91 */
92 public function getLink(): string
93 {
94 return $this->moderationQueue->getLink() . '#comments';
95 }
96
97 /**
98 * @inheritDoc
99 */
100 public function getMessage()
101 {
102 $authors = $this->getAuthors();
103 if (\count($authors) > 1) {
104 if (isset($authors[0])) {
105 unset($authors[0]);
106 }
107 $count = \count($authors);
108
109 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix . '.comment.message.stacked', [
110 'author' => $this->author,
111 'authors' => \array_values($authors),
112 'count' => $count,
113 'others' => $count - 1,
114 'moderationQueue' => $this->moderationQueue,
115 ]);
116 }
117
118 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix . '.comment.message', [
119 'author' => $this->author,
120 'commentID' => $this->getUserNotificationObject()->commentID,
121 'moderationQueue' => $this->moderationQueue,
122 ]);
123 }
124
125 /**
126 * @inheritDoc
127 */
128 protected function prepare()
129 {
130 }
131
132 /**
133 * @inheritDoc
134 */
135 public function setObject(
136 UserNotification $notification,
137 IUserNotificationObject $object,
138 UserProfile $author,
139 array $additionalData = []
140 ) {
141 parent::setObject($notification, $object, $author, $additionalData);
142
143 $this->moderationQueue = new ViewableModerationQueue(
144 new ModerationQueue($this->getUserNotificationObject()->objectID)
145 );
146
147 /** @var IModerationQueueHandler $moderationHandler */
148 $moderationHandler = ObjectTypeCache::getInstance()
149 ->getObjectType($this->moderationQueue->objectTypeID)
150 ->getProcessor();
151 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
152 $this->typeName = $this->getLanguage()->get($moderationHandler->getCommentNotificationTypeNameLanguageItem());
153 }
154
155 /**
156 * @inheritDoc
157 * @since 3.1
158 */
159 public static function canBeTriggeredByGuests()
160 {
161 return false;
162 }
163
164 /**
165 * @inheritDoc
166 * @since 3.1
167 */
168 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
169 {
170 return [
171 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
172 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue'),
173 ];
174 }
175
176 /**
177 * @inheritDoc
178 */
179 protected function getTypeName(): string
180 {
181 return $this->typeName;
182 }
183
184 /**
185 * @inheritDoc
186 */
187 protected function getObjectTitle(): string
188 {
189 return $this->moderationQueue->getTitle();
190 }
191 }