2017-12-17 20:57:05 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
2017-12-17 20:57:05 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Models\Location;
|
2022-10-14 16:59:20 +00:00
|
|
|
use League\Fractal\Resource\Collection;
|
|
|
|
use League\Fractal\Resource\NullResource;
|
2018-01-13 02:39:15 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2022-12-15 00:05:46 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2017-12-17 20:57:05 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
class LocationTransformer extends Transformer
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* List of resources that can be included.
|
|
|
|
*/
|
2022-05-04 23:11:42 +00:00
|
|
|
protected array $availableIncludes = ['nodes', 'servers'];
|
2017-12-17 20:57:05 +00:00
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
*/
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return Location::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
2017-12-17 20:57:05 +00:00
|
|
|
/**
|
2020-09-13 18:13:37 +00:00
|
|
|
* Return a generic transformed location array.
|
2017-12-17 20:57:05 +00:00
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
public function transform(Location $model): array
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
2018-03-04 22:30:16 +00:00
|
|
|
return [
|
2022-12-15 00:05:46 +00:00
|
|
|
'id' => $model->id,
|
|
|
|
'short' => $model->short,
|
|
|
|
'long' => $model->long,
|
|
|
|
'created_at' => self::formatTimestamp($model->created_at),
|
|
|
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
2018-03-04 22:30:16 +00:00
|
|
|
];
|
2017-12-17 20:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the nodes associated with this location.
|
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
public function includeNodes(Location $location): Collection|NullResource
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
2022-12-15 00:05:46 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
2018-01-13 02:39:15 +00:00
|
|
|
return $this->null();
|
2017-12-17 20:57:05 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
return $this->collection($location->nodes, new NodeTransformer());
|
2017-12-17 20:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the nodes associated with this location.
|
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
public function includeServers(Location $location): Collection|NullResource
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
2022-12-15 00:05:46 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
2018-01-13 02:39:15 +00:00
|
|
|
return $this->null();
|
2017-12-17 20:57:05 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
return $this->collection($location->servers, new ServerTransformer());
|
2017-12-17 20:57:05 +00:00
|
|
|
}
|
|
|
|
}
|