misc_pterodactyl-panel/app/Transformers/Api/Application/NestTransformer.php

64 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\Nest;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\NullResource;
use Pterodactyl\Services\Acl\Api\AdminAcl;
2022-12-15 00:05:46 +00:00
use Pterodactyl\Transformers\Api\Transformer;
2022-12-15 00:05:46 +00:00
class NestTransformer extends Transformer
{
/**
* Relationships that can be loaded onto this transformation.
*/
2022-12-15 00:05:46 +00:00
protected array $availableIncludes = ['eggs', 'servers'];
/**
* 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.
*/
public function transform(Nest $model): array
{
$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);
return $response;
}
/**
* Include the Eggs relationship on the given Nest model transformation.
*/
public function includeEggs(Nest $model): Collection|NullResource
{
2021-01-23 20:33:34 +00:00
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
2022-12-15 00:05:46 +00:00
return $this->collection($model->eggs, new EggTransformer());
}
2018-03-25 22:41:36 +00:00
/**
* Include the servers relationship on the given Nest model.
*/
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
}
}