2 namespace wcf\system\user\notification\event;
3 use wcf\data\article\category\ArticleCategory;
4 use wcf\data\user\UserProfile;
5 use wcf\system\cache\runtime\CommentRuntimeCache;
6 use wcf\system\cache\runtime\UserProfileRuntimeCache;
7 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
8 use wcf\system\comment\CommentHandler;
9 use wcf\system\email\Email;
10 use wcf\system\user\notification\object\CommentUserNotificationObject;
13 * User notification event for article comment responses.
15 * @author Joshua Rusweg
16 * @copyright 2001-2018 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\System\User\Notification\Event
21 * @method CommentUserNotificationObject getUserNotificationObject()
23 class ArticleCommentResponseOwnerUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
24 use TTestableCommentResponseUserNotificationEvent;
25 use TTestableArticleUserNotificationEvent;
26 use TTestableCategorizedUserNotificationEvent;
31 protected $stackable = true;
36 protected function prepare() {
37 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
43 public function getTitle() {
44 $count = count($this->getAuthors());
46 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.title.stacked', [
48 'timesTriggered' => $this->notification->timesTriggered
52 return $this->getLanguage()->get('wcf.user.notification.articleComment.responseOwner.title');
58 public function getMessage() {
59 $authors = $this->getAuthors();
60 if (count($authors) > 1) {
61 if (isset($authors[0])) {
64 $count = count($authors);
66 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.message.stacked', [
67 'author' => $this->author,
68 'authors' => array_values($authors),
69 'commentID' => $this->getUserNotificationObject()->commentID,
70 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
72 'others' => $count - 1,
73 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
74 'responseID' => $this->getUserNotificationObject()->responseID,
75 'commentAuthor' => $this->getCommentAuthorProfile()
79 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.message', [
80 'author' => $this->author,
81 'commentID' => $this->getUserNotificationObject()->commentID,
82 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
83 'responseID' => $this->getUserNotificationObject()->responseID,
84 'commentAuthor' => $this->getCommentAuthorProfile()
91 public function getEmailMessage($notificationType = 'instant') {
92 $messageID = '<com.woltlab.wcf.user.articleComment.notification/'.$this->getUserNotificationObject()->commentID.'@'.Email::getHost().'>';
95 'template' => 'email_notification_commentResponseOwner',
96 'in-reply-to' => [$messageID],
97 'references' => [$messageID],
98 'application' => 'wcf',
100 'commentID' => $this->getUserNotificationObject()->commentID,
101 'article' => ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID']),
102 'languageVariablePrefix' => 'wcf.user.notification.articleComment.responseOwner',
103 'responseID' => $this->getUserNotificationObject()->responseID,
104 'commentAuthor' => $this->getCommentAuthorProfile(),
110 * Returns the comment authors profile.
112 * @return UserProfile
114 private function getCommentAuthorProfile() {
115 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
117 if ($comment->userID) {
118 return UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
121 return UserProfile::getGuestUserProfile($comment->username);
128 public function getLink() {
129 return ViewableArticleRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#comment'. $this->getUserNotificationObject()->commentID;
135 public function getEventHash() {
136 return sha1($this->eventID . '-' . $this->notification->objectID);
142 protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author) {
144 'objectID' => self::getTestArticle(self::createTestCategory(ArticleCategory::OBJECT_TYPE_NAME), $author)->articleID,
145 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.articleComment')