7b31e084ed71f8ac1373fa23cbab8a1c706d8ca2
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\article\category\ArticleCategory;
4 use wcf\data\article\LikeableArticle;
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
7 use wcf\system\user\notification\object\LikeUserNotificationObject;
8 use wcf\system\user\storage\UserStorageHandler;
9 use wcf\system\WCF;
10
11 /**
12 * User notification event for post likes.
13 *
14 * @author Matthias Schmidt
15 * @copyright 2001-2020 WoltLab GmbH
16 * @license WoltLab License <http://www.woltlab.com/license-agreement.html>
17 * @package WoltLabSuite\Core\System\User\Notification\Event
18 * @since 5.3
19 *
20 * @method LikeUserNotificationObject getUserNotificationObject()
21 */
22 class ArticleLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
23 use TTestableLikeUserNotificationEvent {
24 TTestableLikeUserNotificationEvent::canBeTriggeredByGuests insteadof TTestableUserNotificationEvent;
25 }
26 use TTestableArticleUserNotificationEvent;
27 use TTestableCategorizedUserNotificationEvent;
28 use TTestableUserNotificationEvent;
29 use TReactionUserNotificationEvent;
30
31 /**
32 * @inheritDoc
33 */
34 protected $stackable = true;
35
36 /**
37 * @inheritDoc
38 */
39 protected function prepare() {
40 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID);
41 }
42
43 /**
44 * @inheritDoc
45 */
46 public function getTitle() {
47 $count = count($this->getAuthors());
48 if ($count > 1) {
49 return $this->getLanguage()->getDynamicVariable('wcf.article.like.notification.title.stacked', [
50 'count' => $count,
51 'timesTriggered' => $this->notification->timesTriggered
52 ]);
53 }
54
55 return $this->getLanguage()->getDynamicVariable('wcf.article.like.notification.title');
56 }
57
58 /**
59 * @inheritDoc
60 */
61 public function getMessage() {
62 $article = ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID);
63 $authors = array_values($this->getAuthors());
64 $count = count($authors);
65
66 if ($count > 1) {
67 return $this->getLanguage()->getDynamicVariable('wcf.article.like.notification.message.stacked', [
68 'author' => $this->author,
69 'authors' => $authors,
70 'count' => $count,
71 'others' => $count - 1,
72 'article' => $article,
73 'reactions' => $this->getReactionsForAuthors(),
74 ]);
75 }
76
77 return $this->getLanguage()->getDynamicVariable('wcf.article.like.notification.message', [
78 'author' => $this->author,
79 'article' => $article,
80 'userNotificationObject' => $this->getUserNotificationObject(),
81 'reactions' => $this->getReactionsForAuthors(),
82 ]);
83 }
84
85 /** @noinspection PhpMissingParentCallCommonInspection */
86 /**
87 * @inheritDoc
88 */
89 public function getEmailMessage($notificationType = 'instant') {
90 // not supported
91 }
92
93 /**
94 * @inheritDoc
95 */
96 public function getLink() {
97 return ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)->getLink();
98 }
99
100 /** @noinspection PhpMissingParentCallCommonInspection */
101 /**
102 * @inheritDoc
103 */
104 public function supportsEmailNotification() {
105 return false;
106 }
107
108 /** @noinspection PhpMissingParentCallCommonInspection */
109 /**
110 * @inheritDoc
111 */
112 public function getEventHash() {
113 return sha1($this->eventID . '-' . $this->additionalData['objectID']);
114 }
115
116 /** @noinspection PhpMissingParentCallCommonInspection */
117 /**
118 * @inheritDoc
119 */
120 public function checkAccess() {
121 if (!ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)->canRead()) {
122 UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'wbbUnreadWatchedThreads');
123 UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadArticles');
124 UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadWatchedArticles');
125 UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadArticlesByCategory');
126
127 return false;
128 }
129
130 return true;
131 }
132
133 /**
134 * @inheritDoc
135 */
136 protected static function createTestLikeObject(UserProfile $recipient, UserProfile $author) {
137 return new LikeableArticle(self::getTestArticle(self::createTestCategory(ArticleCategory::OBJECT_TYPE_NAME), $author));
138 }
139
140 /**
141 * @inheritDoc
142 */
143 protected static function getTestLikeableObjectTypeName() {
144 return 'com.woltlab.wcf.likeableArticle';
145 }
146 }