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