2018-01-27 18:38:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Egg;
|
|
|
|
use Pterodactyl\Models\Nest;
|
2018-03-25 22:41:36 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2018-01-27 18:38:56 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
|
|
|
|
|
|
|
class NestTransformer extends BaseTransformer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Relationships that can be loaded onto this transformation.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2022-05-04 23:11:42 +00:00
|
|
|
protected array $availableIncludes = [
|
2018-01-27 18:38:56 +00:00
|
|
|
'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.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Nest $model)
|
|
|
|
{
|
|
|
|
$response = $model->toArray();
|
|
|
|
|
|
|
|
$response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at);
|
|
|
|
$response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include the Eggs relationship on the given Nest model transformation.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
2018-03-25 22:41:36 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
2018-01-27 18:38:56 +00:00
|
|
|
*/
|
|
|
|
public function includeEggs(Nest $model)
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
$model->loadMissing('eggs');
|
|
|
|
|
|
|
|
return $this->collection($model->getRelation('eggs'), $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);
|
|
|
|
}
|
2018-03-25 22:41:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include the servers relationship on the given Nest model.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
|
|
*/
|
|
|
|
public function includeServers(Nest $model)
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
$model->loadMissing('servers');
|
|
|
|
|
|
|
|
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
|
|
|
|
}
|
2018-01-27 18:38:56 +00:00
|
|
|
}
|