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