771e7a0123786d18259a53cd072ac7f12bdb5529
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
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;
17
18 /**
19 * Notification event for receiving a user trophy.
20 *
21 * @author Joshua Ruesweg
22 * @copyright 2001-2019 WoltLab GmbH
23 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
24 *
25 * @method UserTrophyNotificationObject getUserNotificationObject()
26 */
27 class UserTrophyReceivedNotificationEvent extends AbstractUserNotificationEvent implements
28 ITestableUserNotificationEvent
29 {
30 use TTestableCategorizedUserNotificationEvent;
31 use TTestableUserNotificationEvent;
32
33 /**
34 * @inheritDoc
35 */
36 public function getTitle(): string
37 {
38 return $this->getLanguage()->get('wcf.user.notification.trophy.received.title');
39 }
40
41 /**
42 * @inheritDoc
43 */
44 public function getMessage()
45 {
46 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.trophy.received.message', [
47 'userTrophy' => $this->userNotificationObject,
48 'author' => $this->author,
49 ]);
50 }
51
52 /**
53 * @inheritDoc
54 */
55 public function supportsEmailNotification()
56 {
57 return false;
58 }
59
60 /**
61 * @inheritDoc
62 */
63 public function getLink(): string
64 {
65 return $this->getUserNotificationObject()->getTrophy()->getLink();
66 }
67
68 /**
69 * @inheritDoc
70 */
71 public function checkAccess()
72 {
73 return $this->getUserNotificationObject()->getDecoratedObject()->canSee();
74 }
75
76 /**
77 * @inheritDoc
78 * @return UserTrophyNotificationObject[]
79 * @since 3.1
80 */
81 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
82 {
83 /** @var Trophy $trophy */
84 $trophy = (new TrophyAction([], 'create', [
85 'data' => [
86 'title' => 'Trophy Title',
87 'description' => 'Trophy Description',
88 'categoryID' => self::createTestCategory(TrophyCategory::OBJECT_TYPE_NAME)->categoryID,
89 'type' => Trophy::TYPE_BADGE,
90 'isDisabled' => 0,
91 'awardAutomatically' => 0,
92 'iconName' => 'trophy',
93 'iconColor' => 'rgba(255, 255, 255, 1)',
94 'badgeColor' => 'rgba(50, 92, 132, 1)',
95 ],
96 ]))->executeAction()['returnValues'];
97
98 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(TrophyCacheBuilder::getInstance());
99 TrophyCache::getInstance()->clearCache();
100 TrophyCache::getInstance()->init();
101
102 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(CategoryCacheBuilder::getInstance());
103 CategoryCacheBuilder::getInstance()->reset();
104 TrophyCategoryCache::getInstance()->init();
105
106 /** @var UserTrophy $userTrophy */
107 $userTrophy = (new UserTrophyAction([], 'create', [
108 'data' => [
109 'trophyID' => $trophy->trophyID,
110 'userID' => $recipient->userID,
111 'description' => 'User Trophy Description',
112 'time' => TIME_NOW,
113 'useCustomDescription' => 1,
114 ],
115 ]))->executeAction()['returnValues'];
116
117 return [new UserTrophyNotificationObject($userTrophy)];
118 }
119 }