e50081ef74e50482a9d0195758521ffab9330a8f
[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\event\AbstractSharedUserNotificationEvent;
7 use wcf\system\user\notification\event\ITestableUserNotificationEvent;
8 use wcf\system\user\notification\event\TReactionUserNotificationEvent;
9 use wcf\system\user\notification\event\TTestableCommentLikeUserNotificationEvent;
10 use wcf\system\user\notification\object\LikeUserNotificationObject;
11
12 /**
13 * User notification event for article comment likes.
14 *
15 * @author Marcel Werk
16 * @copyright 2001-2022 WoltLab GmbH
17 * @license WoltLab License <http://www.woltlab.com/license-agreement.html>
18 * @package WoltLabSuite\Core\System\User\Notification\Event
19 * @since 5.5
20 *
21 * @method LikeUserNotificationObject getUserNotificationObject()
22 */
23 class ArticleCommentLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent implements
24 ITestableUserNotificationEvent
25 {
26 use TTestableCommentLikeUserNotificationEvent;
27 use TTestableArticleCommentUserNotificationEvent;
28 use TReactionUserNotificationEvent;
29
30 /**
31 * @inheritDoc
32 */
33 protected $stackable = true;
34
35 /**
36 * @inheritDoc
37 */
38 protected function prepare()
39 {
40 ViewableArticleContentRuntimeCache::getInstance()->cacheObjectID($this->additionalData['objectID']);
41 }
42
43 /**
44 * @inheritDoc
45 */
46 public function getTitle()
47 {
48 $count = \count($this->getAuthors());
49 if ($count > 1) {
50 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.like.title.stacked', [
51 'count' => $count,
52 'timesTriggered' => $this->notification->timesTriggered,
53 ]);
54 }
55
56 return $this->getLanguage()->get('wcf.user.notification.articleComment.like.title');
57 }
58
59 /**
60 * @inheritDoc
61 */
62 public function getMessage()
63 {
64 $article = ViewableArticleContentRuntimeCache::getInstance()->getObject($this->additionalData['objectID']);
65 $authors = \array_values($this->getAuthors());
66 $count = \count($authors);
67
68 if ($count > 1) {
69 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.like.message.stacked', [
70 'author' => $this->author,
71 'authors' => $authors,
72 'commentID' => $this->getCommentID(),
73 'count' => $count,
74 'others' => $count - 1,
75 'article' => $article,
76 'reactions' => $this->getReactionsForAuthors(),
77 ]);
78 }
79
80 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.like.message', [
81 'author' => $this->author,
82 'commentID' => $this->getCommentID(),
83 'article' => $article,
84 'reactions' => $this->getReactionsForAuthors(),
85 ]);
86 }
87
88 /**
89 * @inheritDoc
90 */
91 public function getEmailMessage($notificationType = 'instant')
92 {
93 // not supported
94 }
95
96 /**
97 * @inheritDoc
98 */
99 public function getLink()
100 {
101 return ViewableArticleContentRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . '#comment' . $this->getCommentID();
102 }
103
104 /**
105 * @inheritDoc
106 */
107 public function getEventHash()
108 {
109 return \sha1($this->eventID . '-' . $this->getCommentID());
110 }
111
112 /**
113 * @inheritDoc
114 */
115 public function supportsEmailNotification()
116 {
117 return false;
118 }
119
120 /**
121 * Returns the liked comment's id.
122 *
123 * @return int
124 */
125 protected function getCommentID()
126 {
127 // this is the `wcfN_like.objectID` value
128 return $this->getUserNotificationObject()->objectID;
129 }
130 }