2017-04-02 04:49:53 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
2017-04-02 04:49:53 +00:00
|
|
|
|
2017-04-02 20:51:56 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2018-01-12 04:49:46 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2017-04-02 04:49:53 +00:00
|
|
|
|
2018-01-12 04:49:46 +00:00
|
|
|
class UserTransformer extends BaseTransformer
|
2017-04-02 04:49:53 +00:00
|
|
|
{
|
2017-04-09 19:31:10 +00:00
|
|
|
/**
|
|
|
|
* List of resources that can be included.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-11-19 22:30:00 +00:00
|
|
|
protected $availableIncludes = ['servers'];
|
2017-04-08 16:05:29 +00:00
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return User::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
2017-04-02 04:49:53 +00:00
|
|
|
/**
|
2017-04-02 20:51:56 +00:00
|
|
|
* Return a generic transformed subuser array.
|
2017-04-02 04:49:53 +00:00
|
|
|
*
|
2017-11-19 22:30:00 +00:00
|
|
|
* @param \Pterodactyl\Models\User $user
|
2017-04-02 04:49:53 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2017-11-19 22:30:00 +00:00
|
|
|
public function transform(User $user): array
|
2017-04-02 04:49:53 +00:00
|
|
|
{
|
2017-04-02 20:51:56 +00:00
|
|
|
return $user->toArray();
|
2017-04-02 04:49:53 +00:00
|
|
|
}
|
2017-04-09 19:31:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the servers associated with this user.
|
|
|
|
*
|
2017-11-19 22:30:00 +00:00
|
|
|
* @param \Pterodactyl\Models\User $user
|
2018-01-12 04:49:46 +00:00
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
2017-04-09 19:31:10 +00:00
|
|
|
*/
|
|
|
|
public function includeServers(User $user)
|
|
|
|
{
|
2018-01-12 04:49:46 +00:00
|
|
|
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
|
|
|
return $this->null();
|
2017-04-09 19:31:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 05:19:03 +00:00
|
|
|
$user->loadMissing('servers');
|
2017-04-09 19:31:10 +00:00
|
|
|
|
2018-01-12 04:49:46 +00:00
|
|
|
return $this->collection($user->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');
|
2017-04-09 19:31:10 +00:00
|
|
|
}
|
2017-04-02 04:49:53 +00:00
|
|
|
}
|