1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-23 09:32:29 +01:00
Pterodactyl-Panel/app/Transformers/Api/Client/SubuserTransformer.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2019-11-03 21:20:11 +01:00
<?php
namespace Pterodactyl\Transformers\Api\Client;
use Pterodactyl\Models\User;
2019-11-03 21:20:11 +01:00
use Pterodactyl\Models\Subuser;
class SubuserTransformer extends BaseClientTransformer
{
/**
* @var array
*/
protected $defaultIncludes = ['user'];
2019-11-03 21:20:11 +01:00
/**
* Return the resource name for the JSONAPI output.
*
* @return string
*/
public function getResourceName(): string
{
return Subuser::RESOURCE_NAME;
}
/**
* Transforms a subuser into a model that can be shown to a front-end user.
2019-11-03 21:20:11 +01:00
*
* @param \Pterodactyl\Models\Subuser $model
* @return array|void
2019-11-03 21:20:11 +01:00
*/
public function transform(Subuser $model)
{
return [
'permissions' => $model->permissions->pluck('permission'),
2019-11-03 21:20:11 +01:00
];
}
/**
* Include the permissions associated with this subuser.
*
* @param \Pterodactyl\Models\Subuser $model
* @return \League\Fractal\Resource\Item
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
2019-11-03 21:20:11 +01:00
*/
public function includeUser(Subuser $model)
2019-11-03 21:20:11 +01:00
{
return $this->item($model->user, $this->makeTransformer(UserTransformer::class), User::RESOURCE_NAME);
2019-11-03 21:20:11 +01:00
}
}