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