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\CommentRuntimeCache;
6 use wcf\system\cache\runtime\UserProfileRuntimeCache;
7 use wcf\system\comment\CommentHandler;
8 use wcf\system\email\Email;
9 use wcf\system\user\notification\object\CommentUserNotificationObject;
12 * User notification event for page comments.
14 * @author Joshua Rusweg
15 * @copyright 2001-2018 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\User\Notification\Event
20 * @method CommentUserNotificationObject getUserNotificationObject()
22 class PageCommentResponseUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
23 use TTestableCommentResponseUserNotificationEvent;
24 use TTestablePageUserNotificationEvent;
29 protected $stackable = true;
34 protected function prepare() {
35 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
41 public function getTitle() {
42 $count = count($this->getAuthors());
44 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.response.title.stacked', [
46 'timesTriggered' => $this->notification->timesTriggered
50 return $this->getLanguage()->get('wcf.user.notification.pageComment.response.title');
56 public function getMessage() {
57 $authors = $this->getAuthors();
58 if (count($authors) > 1) {
59 if (isset($authors[0])) {
62 $count = count($authors);
64 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.response.message.stacked', [
65 'author' => $this->author,
66 'authors' => array_values($authors),
67 'commentID' => $this->getUserNotificationObject()->commentID,
68 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
70 'others' => $count - 1,
71 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
72 'commentAuthor' => $this->getCommentAuthorProfile()
76 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.response.message', [
77 'author' => $this->author,
78 'commentID' => $this->getUserNotificationObject()->commentID,
79 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
80 'responseID' => $this->getUserNotificationObject()->responseID,
81 'commentAuthor' => $this->getCommentAuthorProfile()
88 public function getEmailMessage($notificationType = 'instant') {
89 $messageID = '<com.woltlab.wcf.user.pageComment.notification/'.$this->getUserNotificationObject()->commentID.'@'.Email::getHost().'>';
92 'template' => 'email_notification_commentResponse',
93 'in-reply-to' => [$messageID],
94 'references' => [$messageID],
95 'application' => 'wcf',
97 'commentID' => $this->getUserNotificationObject()->commentID,
98 'page' => PageCache::getInstance()->getPage($this->additionalData['objectID']),
99 'languageVariablePrefix' => 'wcf.user.notification.pageComment.response',
100 'responseID' => $this->getUserNotificationObject()->responseID,
101 'commentAuthor' => $this->getCommentAuthorProfile()
107 * Returns the comment authors profile.
109 * @return UserProfile
111 private function getCommentAuthorProfile() {
112 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
114 if ($comment->userID) {
115 return UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
118 return UserProfile::getGuestUserProfile($comment->username);
125 public function getLink() {
126 return PageCache::getInstance()->getPage($this->additionalData['objectID'])->getLink() . '#comment'. $this->getUserNotificationObject()->commentID;
132 public function getEventHash() {
133 return sha1($this->eventID . '-' . $this->notification->objectID);
139 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
141 'objectID' => self::getTestPage()->pageID,
142 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.page')