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