d4e42842cf5d53450b7f969bb1c23b249e87cf83
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\CommentRuntimeCache;
7 use wcf\system\cache\runtime\UserProfileRuntimeCache;
8 use wcf\system\cache\runtime\ViewableArticleContentRuntimeCache;
9 use wcf\system\email\Email;
10
11 /**
12 * User notification event for article comment responses.
13 *
14 * @author Joshua Ruesweg
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @since 5.2
18 */
19 class ArticleCommentResponseOwnerUserNotificationEvent extends AbstractCommentResponseUserNotificationEvent implements
20 ITestableUserNotificationEvent
21 {
22 use TTestableCommentResponseUserNotificationEvent;
23 use TTestableArticleCommentUserNotificationEvent;
24
25 /**
26 * @inheritDoc
27 */
28 public function getMessage()
29 {
30 $authors = $this->getAuthors();
31 if (\count($authors) > 1) {
32 if (isset($authors[0])) {
33 unset($authors[0]);
34 }
35 $count = \count($authors);
36
37 return $this->getLanguage()->getDynamicVariable(
38 'wcf.user.notification.articleComment.responseOwner.message.stacked',
39 [
40 'author' => $this->author,
41 'authors' => \array_values($authors),
42 'commentID' => $this->getUserNotificationObject()->commentID,
43 'article' => ViewableArticleContentRuntimeCache::getInstance()
44 ->getObject($this->additionalData['objectID']),
45 'count' => $count,
46 'others' => $count - 1,
47 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
48 'responseID' => $this->getUserNotificationObject()->responseID,
49 'commentAuthor' => $this->getCommentAuthorProfile(),
50 ]
51 );
52 }
53
54 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.message', [
55 'author' => $this->author,
56 'commentID' => $this->getUserNotificationObject()->commentID,
57 'article' => ViewableArticleContentRuntimeCache::getInstance()
58 ->getObject($this->additionalData['objectID']),
59 'responseID' => $this->getUserNotificationObject()->responseID,
60 'commentAuthor' => $this->getCommentAuthorProfile(),
61 ]);
62 }
63
64 /**
65 * @inheritDoc
66 */
67 public function getEmailMessage($notificationType = 'instant')
68 {
69 $messageID = '<com.woltlab.wcf.user.articleComment.notification/' . $this->getUserNotificationObject()->commentID . '@' . Email::getHost() . '>';
70
71 return [
72 'template' => 'email_notification_commentResponseOwner',
73 'in-reply-to' => [$messageID],
74 'references' => [$messageID],
75 'application' => 'wcf',
76 'variables' => [
77 'commentID' => $this->getUserNotificationObject()->commentID,
78 'article' => ViewableArticleContentRuntimeCache::getInstance()
79 ->getObject($this->additionalData['objectID']),
80 'languageVariablePrefix' => 'wcf.user.notification.articleComment.responseOwner',
81 'responseID' => $this->getUserNotificationObject()->responseID,
82 'commentAuthor' => $this->getCommentAuthorProfile(),
83 ],
84 ];
85 }
86
87 /**
88 * Returns the comment authors profile.
89 *
90 * @return UserProfile
91 */
92 private function getCommentAuthorProfile()
93 {
94 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
95
96 if ($comment->userID) {
97 return UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
98 } else {
99 return UserProfile::getGuestUserProfile($comment->username);
100 }
101 }
102
103 /**
104 * @inheritDoc
105 */
106 public function getLink(): string
107 {
108 return ViewableArticleContentRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#comment' . $this->getUserNotificationObject()->commentID . '/response' . $this->getUserNotificationObject()->responseID;
109 }
110
111 /**
112 * @inheritDoc
113 */
114 protected function getTypeName(): string
115 {
116 return $this->getLanguage()->get('wcf.user.recentActivity.com.woltlab.wcf.article.recentActivityEvent');
117 }
118
119 /**
120 * @inheritDoc
121 */
122 protected function getObjectTitle(): string
123 {
124 return ViewableArticleContentRuntimeCache::getInstance()
125 ->getObject($this->additionalData['objectID'])->getTitle();
126 }
127 }