3 namespace wcf\system\user\notification\event;
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\CommentRuntimeCache;
7 use wcf\system\cache\runtime\UserProfileRuntimeCache;
8 use wcf\system\comment\CommentHandler;
9 use wcf\system\email\Email;
10 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
13 * User notification event for profile's owner for comment responses.
15 * @author Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @method CommentResponseUserNotificationObject getUserNotificationObject()
21 class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractSharedUserNotificationEvent implements
22 ITestableUserNotificationEvent
24 use TTestableCommentResponseUserNotificationEvent;
29 protected $stackable = true;
34 protected function prepare()
36 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
37 UserProfileRuntimeCache::getInstance()->cacheObjectIDs([
38 $this->additionalData['userID'],
39 $this->additionalData['objectID'],
46 public function getTitle(): string
48 $count = \count($this->getAuthors());
50 return $this->getLanguage()->getDynamicVariable(
51 'wcf.user.notification.commentResponseOwner.title.stacked',
54 'timesTriggered' => $this->notification->timesTriggered,
59 return $this->getLanguage()->get('wcf.user.notification.commentResponseOwner.title');
65 public function getMessage()
67 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
68 if ($comment->userID) {
69 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
71 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
74 $authors = $this->getAuthors();
75 if (\count($authors) > 1) {
76 if (isset($authors[0])) {
79 $count = \count($authors);
81 return $this->getLanguage()->getDynamicVariable(
82 'wcf.user.notification.commentResponseOwner.message.stacked',
84 'author' => $commentAuthor,
85 'authors' => \array_values($authors),
87 'others' => $count - 1,
88 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
89 'commentID' => $this->getUserNotificationObject()->commentID,
94 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.commentResponseOwner.message', [
95 'author' => $this->author,
96 'commentAuthor' => $commentAuthor,
97 'commentID' => $this->getUserNotificationObject()->commentID,
98 'responseID' => $this->getUserNotificationObject()->responseID,
105 public function getEmailMessage($notificationType = 'instant')
107 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
108 $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
109 if ($comment->userID) {
110 $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
112 $commentAuthor = UserProfile::getGuestUserProfile($comment->username);
115 $messageID = '<com.woltlab.wcf.user.profileComment.notification/' . $comment->commentID . '@' . Email::getHost() . '>';
118 'template' => 'email_notification_commentResponseOwner',
119 'application' => 'wcf',
120 'in-reply-to' => [$messageID],
121 'references' => [$messageID],
123 'commentAuthor' => $commentAuthor,
124 'commentID' => $this->getUserNotificationObject()->commentID,
126 'responseID' => $this->getUserNotificationObject()->responseID,
127 'languageVariablePrefix' => 'wcf.user.notification.commentResponseOwner',
135 public function getLink(): string
137 return UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink()
138 . '#wall/comment' . $this->getUserNotificationObject()->commentID;
144 public function getEventHash()
146 return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->commentID);
153 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
156 'objectID' => $recipient->userID,
157 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user.profileComment'),