39bcc951f399ce77a8fa9562a07830ae06a2f5f8
[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 AbstractSharedUserNotificationEvent implements
23 ITestableUserNotificationEvent
24 {
25 use TTestableCommentResponseUserNotificationEvent;
26 use TTestableArticleCommentUserNotificationEvent;
27
28 /**
29 * @inheritDoc
30 */
31 protected $stackable = true;
32
33 /**
34 * @inheritDoc
35 */
36 protected function prepare()
37 {
38 CommentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->commentID);
39 }
40
41 /**
42 * @inheritDoc
43 */
44 public function getTitle(): string
45 {
46 $count = \count($this->getAuthors());
47 if ($count > 1) {
48 return $this->getLanguage()->getDynamicVariable(
49 'wcf.user.notification.articleComment.responseOwner.title.stacked',
50 [
51 'count' => $count,
52 'timesTriggered' => $this->notification->timesTriggered,
53 ]
54 );
55 }
56
57 return $this->getLanguage()->get('wcf.user.notification.articleComment.responseOwner.title');
58 }
59
60 /**
61 * @inheritDoc
62 */
63 public function getMessage()
64 {
65 $authors = $this->getAuthors();
66 if (\count($authors) > 1) {
67 if (isset($authors[0])) {
68 unset($authors[0]);
69 }
70 $count = \count($authors);
71
72 return $this->getLanguage()->getDynamicVariable(
73 'wcf.user.notification.articleComment.responseOwner.message.stacked',
74 [
75 'author' => $this->author,
76 'authors' => \array_values($authors),
77 'commentID' => $this->getUserNotificationObject()->commentID,
78 'article' => ViewableArticleContentRuntimeCache::getInstance()
79 ->getObject($this->additionalData['objectID']),
80 'count' => $count,
81 'others' => $count - 1,
82 'guestTimesTriggered' => $this->notification->guestTimesTriggered,
83 'responseID' => $this->getUserNotificationObject()->responseID,
84 'commentAuthor' => $this->getCommentAuthorProfile(),
85 ]
86 );
87 }
88
89 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.responseOwner.message', [
90 'author' => $this->author,
91 'commentID' => $this->getUserNotificationObject()->commentID,
92 'article' => ViewableArticleContentRuntimeCache::getInstance()
93 ->getObject($this->additionalData['objectID']),
94 'responseID' => $this->getUserNotificationObject()->responseID,
95 'commentAuthor' => $this->getCommentAuthorProfile(),
96 ]);
97 }
98
99 /**
100 * @inheritDoc
101 */
102 public function getEmailMessage($notificationType = 'instant')
103 {
104 $messageID = '<com.woltlab.wcf.user.articleComment.notification/' . $this->getUserNotificationObject()->commentID . '@' . Email::getHost() . '>';
105
106 return [
107 'template' => 'email_notification_commentResponseOwner',
108 'in-reply-to' => [$messageID],
109 'references' => [$messageID],
110 'application' => 'wcf',
111 'variables' => [
112 'commentID' => $this->getUserNotificationObject()->commentID,
113 'article' => ViewableArticleContentRuntimeCache::getInstance()
114 ->getObject($this->additionalData['objectID']),
115 'languageVariablePrefix' => 'wcf.user.notification.articleComment.responseOwner',
116 'responseID' => $this->getUserNotificationObject()->responseID,
117 'commentAuthor' => $this->getCommentAuthorProfile(),
118 ],
119 ];
120 }
121
122 /**
123 * Returns the comment authors profile.
124 *
125 * @return UserProfile
126 */
127 private function getCommentAuthorProfile()
128 {
129 $comment = CommentRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->commentID);
130
131 if ($comment->userID) {
132 return UserProfileRuntimeCache::getInstance()->getObject($comment->userID);
133 } else {
134 return UserProfile::getGuestUserProfile($comment->username);
135 }
136 }
137
138 /**
139 * @inheritDoc
140 */
141 public function getLink(): string
142 {
143 return ViewableArticleContentRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#comment' . $this->getUserNotificationObject()->commentID . '/response' . $this->getUserNotificationObject()->responseID;
144 }
145
146 /**
147 * @inheritDoc
148 */
149 public function getEventHash()
150 {
151 return \sha1($this->eventID . '-' . $this->notification->objectID);
152 }
153 }