3 namespace wcf\system\user\notification\event;
5 use wcf\data\trophy\category\TrophyCategory;
6 use wcf\data\trophy\category\TrophyCategoryCache;
7 use wcf\data\trophy\Trophy;
8 use wcf\data\trophy\TrophyAction;
9 use wcf\data\trophy\TrophyCache;
10 use wcf\data\user\trophy\UserTrophy;
11 use wcf\data\user\trophy\UserTrophyAction;
12 use wcf\data\user\UserProfile;
13 use wcf\system\cache\builder\CategoryCacheBuilder;
14 use wcf\system\cache\builder\TrophyCacheBuilder;
15 use wcf\system\user\notification\object\UserTrophyNotificationObject;
16 use wcf\system\user\notification\TestableUserNotificationEventHandler;
19 * Notification event for receiving a user trophy.
21 * @author Joshua Ruesweg
22 * @copyright 2001-2019 WoltLab GmbH
23 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
25 * @method UserTrophyNotificationObject getUserNotificationObject()
27 class UserTrophyReceivedNotificationEvent extends AbstractUserNotificationEvent implements
28 ITestableUserNotificationEvent
30 use TTestableCategorizedUserNotificationEvent;
31 use TTestableUserNotificationEvent;
36 public function getTitle(): string
38 return $this->getLanguage()->get('wcf.user.notification.trophy.received.title');
44 public function getMessage()
46 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.trophy.received.message', [
47 'userTrophy' => $this->userNotificationObject,
48 'author' => $this->author,
55 public function supportsEmailNotification()
63 public function getLink(): string
65 return $this->getUserNotificationObject()->getTrophy()->getLink();
71 public function checkAccess()
73 return $this->getUserNotificationObject()->getDecoratedObject()->canSee();
78 * @return UserTrophyNotificationObject[]
81 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
83 /** @var Trophy $trophy */
84 $trophy = (new TrophyAction([], 'create', [
86 'title' => 'Trophy Title',
87 'description' => 'Trophy Description',
88 'categoryID' => self::createTestCategory(TrophyCategory::OBJECT_TYPE_NAME)->categoryID,
89 'type' => Trophy::TYPE_BADGE,
91 'awardAutomatically' => 0,
92 'iconName' => 'trophy',
93 'iconColor' => 'rgba(255, 255, 255, 1)',
94 'badgeColor' => 'rgba(50, 92, 132, 1)',
96 ]))->executeAction()['returnValues'];
98 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(TrophyCacheBuilder::getInstance());
99 TrophyCache::getInstance()->clearCache();
100 TrophyCache::getInstance()->init();
102 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(CategoryCacheBuilder::getInstance());
103 CategoryCacheBuilder::getInstance()->reset();
104 TrophyCategoryCache::getInstance()->init();
106 /** @var UserTrophy $userTrophy */
107 $userTrophy = (new UserTrophyAction([], 'create', [
109 'trophyID' => $trophy->trophyID,
110 'userID' => $recipient->userID,
111 'description' => 'User Trophy Description',
113 'useCustomDescription' => 1,
115 ]))->executeAction()['returnValues'];
117 return [new UserTrophyNotificationObject($userTrophy)];