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