2 namespace wcf\system\user\notification\event;
3 use wcf\data\trophy\category\TrophyCategory;
4 use wcf\data\trophy\category\TrophyCategoryCache;
5 use wcf\data\trophy\Trophy;
6 use wcf\data\trophy\TrophyAction;
7 use wcf\data\trophy\TrophyCache;
8 use wcf\data\user\trophy\UserTrophy;
9 use wcf\data\user\trophy\UserTrophyAction;
10 use wcf\data\user\UserProfile;
11 use wcf\system\cache\builder\CategoryCacheBuilder;
12 use wcf\system\cache\builder\TrophyCacheBuilder;
13 use wcf\system\user\notification\object\UserTrophyNotificationObject;
14 use wcf\system\user\notification\TestableUserNotificationEventHandler;
17 * Notification event for receiving a user trophy.
19 * @author Joshua Ruesweg
20 * @copyright 2001-2017 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 * @package WoltLabSuite\Core\System\User\Notification\Object\Type
24 * @method UserTrophyNotificationObject getUserNotificationObject()
26 class UserTrophyReceivedNotificationEvent extends AbstractUserNotificationEvent implements ITestableUserNotificationEvent {
27 use TTestableCategorizedUserNotificationEvent;
28 use TTestableUserNotificationEvent;
33 public function getTitle() {
34 return $this->getLanguage()->get('wcf.user.notification.trophy.received.title');
40 public function getMessage() {
41 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.trophy.received.message', [
42 'userTrophy' => $this->userNotificationObject,
43 'author' => $this->author
50 public function supportsEmailNotification() {
57 public function getLink() {
58 return $this->getUserNotificationObject()->getTrophy()->getLink();
64 public function checkAccess() {
65 return $this->getUserNotificationObject()->getDecoratedObject()->canSee();
70 * @return UserTrophyNotificationObject[]
73 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
74 /** @var Trophy $trophy */
75 $trophy = (new TrophyAction([], 'create', [
77 'title' => 'Trophy Title',
78 'description' => 'Trophy Description',
79 'categoryID' => self::createTestCategory(TrophyCategory::OBJECT_TYPE_NAME)->categoryID,
80 'type' => Trophy::TYPE_BADGE,
82 'awardAutomatically' => 0,
83 'iconName' => 'trophy',
84 'iconColor' => 'rgba(255, 255, 255, 1)',
85 'badgeColor' => 'rgba(50, 92, 132, 1)'
87 ]))->executeAction()['returnValues'];
89 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(TrophyCacheBuilder::getInstance());
90 TrophyCache::getInstance()->clearCache();
91 TrophyCache::getInstance()->init();
93 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(CategoryCacheBuilder::getInstance());
94 CategoryCacheBuilder::getInstance()->reset();
95 TrophyCategoryCache::getInstance()->init();
97 /** @var UserTrophy $userTrophy */
98 $userTrophy = (new UserTrophyAction([], 'create', [
100 'trophyID' => $trophy->trophyID,
101 'userID' => $recipient->userID,
102 'description' => 'User Trophy Description',
104 'useCustomDescription' => 1
106 ]))->executeAction()['returnValues'];
108 return [new UserTrophyNotificationObject($userTrophy)];