8db7009247ef4b970bea3291471f4a1054619cfc
[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-2017 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 'moderationQueue' => $this->moderationQueue
112 ]);
113 }
114
115 /**
116 * @inheritDoc
117 */
118 public function getTitle() {
119 $count = count($this->getAuthors());
120 if ($count > 1) {
121 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.title.stacked', [
122 'count' => $count,
123 'timesTriggered' => $this->notification->timesTriggered
124 ]);
125 }
126
127 return $this->getLanguage()->get($this->languageItemPrefix.'.comment.title');
128 }
129
130 /**
131 * @inheritDoc
132 */
133 public function setObject(UserNotification $notification, IUserNotificationObject $object, UserProfile $author, array $additionalData = []) {
134 parent::setObject($notification, $object, $author, $additionalData);
135
136 // if the active user has no access, $this->moderationQueue is null
137 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($this->getUserNotificationObject()->objectID);
138
139 if ($this->moderationQueue) {
140 /** @var IModerationQueueHandler $moderationHandler */
141 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->moderationQueue->objectTypeID)->getProcessor();
142 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
143 }
144 }
145
146 /**
147 * @inheritDoc
148 * @since 3.1
149 */
150 public static function canBeTriggeredByGuests() {
151 return false;
152 }
153
154 /**
155 * @inheritDoc
156 * @since 3.1
157 */
158 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
159 return [
160 'objectID' => self::getTestUserModerationQueueEntry($author, $recipient)->queueID,
161 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue')
162 ];
163 }
164 }