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