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;
12 * User notification event for post likes.
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
20 * @method LikeUserNotificationObject getUserNotificationObject()
22 class ArticleLikeUserNotificationEvent extends AbstractSharedUserNotificationEvent implements ITestableUserNotificationEvent {
23 use TTestableLikeUserNotificationEvent {
24 TTestableLikeUserNotificationEvent::canBeTriggeredByGuests insteadof TTestableUserNotificationEvent;
26 use TTestableArticleUserNotificationEvent;
27 use TTestableCategorizedUserNotificationEvent;
28 use TTestableUserNotificationEvent;
29 use TReactionUserNotificationEvent;
34 protected $stackable = true;
39 protected function prepare() {
40 ViewableArticleRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID);
46 public function getTitle() {
47 $count = count($this->getAuthors());
49 return $this->getLanguage()->getDynamicVariable('wcf.article.like.notification.title.stacked', [
51 'timesTriggered' => $this->notification->timesTriggered
55 return $this->getLanguage()->getDynamicVariable('wcf.article.like.notification.title');
61 public function getMessage() {
62 $article = ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID);
63 $authors = array_values($this->getAuthors());
64 $count = count($authors);
67 return $this->getLanguage()->getDynamicVariable('wcf.article.like.notification.message.stacked', [
68 'author' => $this->author,
69 'authors' => $authors,
71 'others' => $count - 1,
72 'article' => $article,
73 'reactions' => $this->getReactionsForAuthors(),
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(),
85 /** @noinspection PhpMissingParentCallCommonInspection */
89 public function getEmailMessage($notificationType = 'instant') {
96 public function getLink() {
97 return ViewableArticleRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)->getLink();
100 /** @noinspection PhpMissingParentCallCommonInspection */
104 public function supportsEmailNotification() {
108 /** @noinspection PhpMissingParentCallCommonInspection */
112 public function getEventHash() {
113 return sha1($this->eventID . '-' . $this->additionalData['objectID']);
116 /** @noinspection PhpMissingParentCallCommonInspection */
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');
136 protected static function createTestLikeObject(UserProfile $recipient, UserProfile $author) {
137 return new LikeableArticle(self::getTestArticle(self::createTestCategory(ArticleCategory::OBJECT_TYPE_NAME), $author));
143 protected static function getTestLikeableObjectTypeName() {
144 return 'com.woltlab.wcf.likeableArticle';