3 namespace wcf\system\user\notification\event;
5 use wcf\data\page\PageCache;
6 use wcf\data\user\UserProfile;
7 use wcf\system\cache\runtime\CommentRuntimeCache;
8 use wcf\system\cache\runtime\UserProfileRuntimeCache;
9 use wcf\system\comment\CommentHandler;
10 use wcf\system\email\Email;
11 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
14 * User notification event for page comments.
16 * @author Joshua Ruesweg
17 * @copyright 2001-2019 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @method CommentResponseUserNotificationObject getUserNotificationObject()
23 class PageCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements
24 ITestableUserNotificationEvent
26 use TTestableCommentResponseUserNotificationEvent;
27 use TTestablePageUserNotificationEvent;
32 protected $stackable = true;
37 protected function prepare()
39 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
45 public function getTitle(): string
47 $count = \count($this->getAuthors());
49 return $this->getLanguage()->getDynamicVariable(
50 'wcf.user.notification.pageComment.response.title.stacked',
53 'timesTriggered' => $this->notification->timesTriggered,
58 return $this->getLanguage()->get('wcf.user.notification.pageComment.response.title');
64 public function getMessage()
66 $authors = $this->getAuthors();
67 if (\count($authors) > 1) {
68 if (isset($authors[0])) {
71 $count = \count($authors);
73 return $this->getLanguage()->getDynamicVariable(
74 'wcf.user.notification.pageComment.response.message.stacked',
76 'author' => $this->author,
77 'authors' => \array_values($authors),
78 'commentID' => $this->getUserNotificationObject()->commentID,
79 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
81 'others' => $count - 1,
82 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
83 'commentAuthor' => $this->getCommentAuthorProfile(),
88 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.response.message', [
89 'author' => $this->author,
90 'commentID' => $this->getUserNotificationObject()->commentID,
91 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
92 'responseID' => $this->getUserNotificationObject()->responseID,
93 'commentAuthor' => $this->getCommentAuthorProfile(),
100 public function getEmailMessage($notificationType = 'instant')
102 $messageID = '<com.woltlab.wcf.user.pageComment.notification/' . $this->getUserNotificationObject()->commentID . '@' . Email::getHost() . '>';
105 'template' => 'email_notification_commentResponse',
106 'in-reply-to' => [$messageID],
107 'references' => [$messageID],
108 'application' => 'wcf',
110 'commentID' => $this->getUserNotificationObject()->commentID,
111 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
112 'languageVariablePrefix' => 'wcf.user.notification.pageComment.response',
113 'responseID' => $this->getUserNotificationObject()->responseID,
114 'commentAuthor' => $this->getCommentAuthorProfile(),
120 * Returns the comment authors profile.
122 * @return UserProfile
124 private function getCommentAuthorProfile()
126 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
128 if ($comment->userID) {
129 return UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
131 return UserProfile::getGuestUserProfile($comment->username);
138 public function getLink(): string
140 return PageCache::getInstance()->getPage($this->additionalData['objectID'])->getLink() . '#comment' . $this->getUserNotificationObject()->commentID;
146 public function getEventHash()
148 return \sha1($this->eventID . '-' . $this->notification->objectID);
154 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
157 'objectID' => self::getTestPage()->pageID,
158 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.page'),