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