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