2 namespace wcf\system\user\notification\event
;
3 use wcf\data\category\CategoryAction
;
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\TrophyCacheBuilder
;
13 use wcf\system\category\CategoryHandler
;
14 use wcf\system\user\notification\
object\UserTrophyNotificationObject
;
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 TTestableUserNotificationEvent
;
32 public function getTitle() {
33 return $this->getLanguage()->get('wcf.user.notification.trophy.received.title');
39 public function getMessage() {
40 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.trophy.received.message', [
41 'userTrophy' => $this->userNotificationObject
,
42 'author' => $this->author
49 public function supportsEmailNotification() {
56 public function getLink() {
57 return $this->getUserNotificationObject()->getTrophy()->getLink();
63 public function checkAccess() {
64 return $this->getUserNotificationObject()->getDecoratedObject()->canSee();
69 * @return UserTrophyNotificationObject[]
72 public static function getTestObjects(UserProfile
$recipient, UserProfile
$author) {
73 /** @var TrophyCategory $trophyCategory */
74 $trophyCategory = null;
75 $trophyCategories = TrophyCategoryCache
::getInstance()->getEnabledCategories();
77 if (empty($trophyCategories)) {
78 $trophyCategory = (new CategoryAction([], 'create', [
80 'description' => 'Trophy Category Description',
82 'objectTypeID' => CategoryHandler
::getInstance()->getObjectType(TrophyCategory
::OBJECT_TYPE_NAME
)->objectTypeID
,
83 'title' => 'Trophy Category'
85 ]))->executeAction()['returnValues'];
88 $trophyCategory = reset($trophyCategories);
91 /** @var Trophy $trophy */
92 $trophy = (new TrophyAction([], 'create', [
94 'title' => 'Trophy Title',
95 'description' => 'Trophy Description',
96 'categoryID' => $trophyCategory->categoryID
,
97 'type' => Trophy
::TYPE_BADGE
,
99 'awardAutomatically' => 0,
100 'iconName' => 'trophy',
101 'iconColor' => 'rgba(255, 255, 255, 1)',
102 'badgeColor' => 'rgba(50, 92, 132, 1)'
104 ]))->executeAction()['returnValues'];
106 /** @var UserTrophy $userTropy */
107 $userTropy = (new UserTrophyAction([], 'create', [
109 'trophyID' => $trophy->trophyID
,
110 'userID' => $recipient->userID
,
111 'description' => 'User Trophy Description',
113 'useCustomDescription' => 1
115 ]))->executeAction()['returnValues'];
117 TrophyCache
::getInstance()->clearCache();
119 // work-around to reset trophy cache during this request
120 $reflectionClass = new \
ReflectionClass(TrophyCacheBuilder
::class);
121 $reflectionProperty = $reflectionClass->getProperty('cache');
122 $reflectionProperty->setAccessible(true);
123 $reflectionProperty->setValue(TrophyCacheBuilder
::getInstance(), []);
125 return [new UserTrophyNotificationObject($userTropy)];