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