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