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