cb073d24637adfd9ffe9f26b30e541f73f6bc503
[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 'notificationType' => $notificationType,
64 'languageItemPrefix' => $this->languageItemPrefix
65 ]
66 ];
67 }
68
69 /**
70 * @inheritDoc
71 */
72 public function getEventHash() {
73 return sha1($this->eventID . '-' . $this->moderationQueue->queueID);
74 }
75
76 /**
77 * @inheritDoc
78 */
79 public function getLink() {
80 return $this->moderationQueue->getLink() . '#comments';
81 }
82
83 /**
84 * @inheritDoc
85 */
86 public function getMessage() {
87 $authors = $this->getAuthors();
88 if (count($authors) > 1) {
89 if (isset($authors[0])) {
90 unset($authors[0]);
91 }
92 $count = count($authors);
93
94 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.message.stacked', [
95 'author' => $this->author,
96 'authors' => array_values($authors),
97 'count' => $count,
98 'others' => $count - 1,
99 'moderationQueue' => $this->moderationQueue
100 ]);
101 }
102
103 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.message', [
104 'author' => $this->author,
105 'moderationQueue' => $this->moderationQueue
106 ]);
107 }
108
109 /**
110 * @inheritDoc
111 */
112 public function getTitle() {
113 $count = count($this->getAuthors());
114 if ($count > 1) {
115 return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix.'.comment.title.stacked', [
116 'count' => $count,
117 'timesTriggered' => $this->notification->timesTriggered
118 ]);
119 }
120
121 return $this->getLanguage()->get($this->languageItemPrefix.'.comment.title');
122 }
123
124 /**
125 * @inheritDoc
126 */
127 public function setObject(UserNotification $notification, IUserNotificationObject $object, UserProfile $author, array $additionalData = []) {
128 parent::setObject($notification, $object, $author, $additionalData);
129
130 // if the active user has no access, $this->moderationQueue is null
131 $this->moderationQueue = ViewableModerationQueue::getViewableModerationQueue($this->userNotificationObject->objectID);
132
133 if ($this->moderationQueue) {
134 /** @var IModerationQueueHandler $moderationHandler */
135 $moderationHandler = ObjectTypeCache::getInstance()->getObjectType($this->moderationQueue->objectTypeID)->getProcessor();
136 $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix();
137 }
138 }
139 }