2017-04-02 04:49:53 +00:00
|
|
|
<?php
|
|
|
|
|
2017-12-17 20:57:05 +00:00
|
|
|
namespace Pterodactyl\Transformers\Api\Admin;
|
2017-04-02 04:49:53 +00:00
|
|
|
|
2017-04-02 20:51:56 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2017-12-17 20:57:05 +00:00
|
|
|
use Pterodactyl\Transformers\Api\ApiTransformer;
|
2017-04-02 04:49:53 +00:00
|
|
|
|
2017-11-19 22:30:00 +00:00
|
|
|
class UserTransformer extends ApiTransformer
|
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
|
|
|
|
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
|
|
|
|
* @return bool|\League\Fractal\Resource\Collection
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\PterodactylException
|
2017-04-09 19:31:10 +00:00
|
|
|
*/
|
|
|
|
public function includeServers(User $user)
|
|
|
|
{
|
2018-01-11 05:19:03 +00:00
|
|
|
if (! $this->authorize('server-list')) {
|
2017-11-19 22:30:00 +00:00
|
|
|
return false;
|
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
|
|
|
|
2017-12-17 20:57:05 +00:00
|
|
|
return $this->collection($user->getRelation('servers'), new ServerTransformer($this->getRequest()), 'server');
|
2017-04-09 19:31:10 +00:00
|
|
|
}
|
2017-04-02 04:49:53 +00:00
|
|
|
}
|