efb47d0568a5796d3fe8f57c2801854ac21c016a
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\page\PageCache;
4 use wcf\data\user\UserProfile;
5 use wcf\system\cache\runtime\UserProfileRuntimeCache;
6 use wcf\system\comment\CommentHandler;
7 use wcf\system\user\notification\object\CommentUserNotificationObject;
8
9 /**
10 * User notification event for page comments.
11 *
12 * @author Joshua Rusweg
13 * @copyright 2001-2018 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\User\Notification\Event
16 * @since 3.2
17 *
18 * @method CommentUserNotificationObject getUserNotificationObject()
19 */
20 class PageCommentUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
21 use TTestableCommentUserNotificationEvent;
22 use TTestablePageUserNotificationEvent;
23
24 /**
25 * @inheritDoc
26 */
27 protected $stackable = true;
28
29 /**
30 * @inheritDoc
31 */
32 protected function prepare() {
33 UserProfileRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID);
34 }
35
36 /**
37 * @inheritDoc
38 */
39 public function getTitle() {
40 $count = count($this->getAuthors());
41 if ($count > 1) {
42 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.title.stacked', [
43 'count' => $count,
44 'timesTriggered' => $this->notification->timesTriggered
45 ]);
46 }
47
48 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.title');
49 }
50
51 /**
52 * @inheritDoc
53 */
54 public function getMessage() {
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('wcf.user.notification.pageComment.message.stacked', [
63 'author' => $this->author,
64 'authors' => array_values($authors),
65 'commentID' => $this->getUserNotificationObject()->commentID,
66 'page' => PageCache::getInstance()->getPage($this->getUserNotificationObject()->objectID),
67 'count' => $count,
68 'others' => $count - 1,
69 'guestTimesTriggered' => $this->notification->guestTimesTriggered
70 ]);
71 }
72
73 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.message', [
74 'author' => $this->author,
75 'commentID' => $this->getUserNotificationObject()->commentID,
76 'page' => PageCache::getInstance()->getPage($this->getUserNotificationObject()->objectID)
77 ]);
78 }
79
80 /**
81 * @inheritDoc
82 */
83 public function getEmailMessage($notificationType = 'instant') {
84 return [
85 'message-id' => 'com.woltlab.wcf.user.pageComment.notification/'.$this->getUserNotificationObject()->commentID,
86 'template' => 'email_notification_comment',
87 'application' => 'wcf',
88 'variables' => [
89 'commentID' => $this->getUserNotificationObject()->commentID,
90 'page' => PageCache::getInstance()->getPage($this->getUserNotificationObject()->objectID),
91 'languageVariablePrefix' => 'wcf.user.notification.pageComment'
92 ]
93 ];
94 }
95
96 /**
97 * @inheritDoc
98 */
99 public function getLink() {
100 return PageCache::getInstance()->getPage($this->getUserNotificationObject()->objectID)->getLink() . '#comment'. $this->getUserNotificationObject()->commentID;
101 }
102
103 /**
104 * @inheritDoc
105 */
106 public function getEventHash() {
107 return sha1($this->eventID . '-' . $this->getUserNotificationObject()->objectID);
108 }
109
110 /**
111 * @inheritDoc
112 */
113 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
114 return [
115 'objectID' => self::getTestPage()->pageID,
116 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.page')
117 ];
118 }
119 }