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