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