2018-01-27 18:38:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Nest;
|
2022-10-14 16:59:20 +00:00
|
|
|
use League\Fractal\Resource\Collection;
|
|
|
|
use League\Fractal\Resource\NullResource;
|
2018-01-27 18:38:56 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2022-12-15 00:05:46 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2018-01-27 18:38:56 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
class NestTransformer extends Transformer
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Relationships that can be loaded onto this transformation.
|
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
protected array $availableIncludes = ['eggs', 'servers'];
|
2018-01-27 18:38:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
*/
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return Nest::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform a Nest model into a representation that can be consumed by the
|
|
|
|
* application API.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function transform(Nest $model): array
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
|
|
|
$response = $model->toArray();
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
$response['created_at'] = self::formatTimestamp($model->created_at);
|
|
|
|
$response['updated_at'] = self::formatTimestamp($model->updated_at);
|
2018-01-27 18:38:56 +00:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include the Eggs relationship on the given Nest model transformation.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function includeEggs(Nest $model): Collection|NullResource
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
2018-01-27 18:38:56 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
return $this->collection($model->eggs, new EggTransformer());
|
2018-01-27 18:38:56 +00:00
|
|
|
}
|
2018-03-25 22:41:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include the servers relationship on the given Nest model.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function includeServers(Nest $model): Collection|NullResource
|
2018-03-25 22:41:36 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
2018-03-25 22:41:36 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
return $this->collection($model->servers, new ServerTransformer());
|
2018-03-25 22:41:36 +00:00
|
|
|
}
|
2018-01-27 18:38:56 +00:00
|
|
|
}
|