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