2019-11-03 21:20:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
2019-12-28 21:03:19 +01:00
|
|
|
use Pterodactyl\Models\User;
|
2019-11-03 21:20:11 +01:00
|
|
|
use Pterodactyl\Models\Subuser;
|
|
|
|
|
|
|
|
class SubuserTransformer extends BaseClientTransformer
|
|
|
|
{
|
2019-12-28 21:03:19 +01:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-28 21:03:19 +01:00
|
|
|
* 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
|
2019-12-28 21:03:19 +01:00
|
|
|
* @return array|void
|
2019-11-03 21:20:11 +01:00
|
|
|
*/
|
|
|
|
public function transform(Subuser $model)
|
|
|
|
{
|
|
|
|
return [
|
2019-12-28 21:03:19 +01:00
|
|
|
'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
|
2019-12-28 21:03:19 +01:00
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
2019-11-03 21:20:11 +01:00
|
|
|
*/
|
2019-12-28 21:03:19 +01:00
|
|
|
public function includeUser(Subuser $model)
|
2019-11-03 21:20:11 +01:00
|
|
|
{
|
2019-12-28 21:03:19 +01:00
|
|
|
return $this->item($model->user, $this->makeTransformer(UserTransformer::class), User::RESOURCE_NAME);
|
2019-11-03 21:20:11 +01:00
|
|
|
}
|
|
|
|
}
|