2018-01-27 18:38:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Nest;
|
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2021-08-07 20:25:06 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2018-01-27 18:38:56 +00:00
|
|
|
|
2021-08-07 20:25:06 +00:00
|
|
|
class NestTransformer extends Transformer
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Relationships that can be loaded onto this transformation.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
2021-08-07 20:25:06 +00:00
|
|
|
'eggs',
|
|
|
|
'servers',
|
2018-01-27 18:38:56 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return Nest::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
2021-08-07 20:25:06 +00:00
|
|
|
public function transform(Nest $model): array
|
2018-01-27 18:38:56 +00:00
|
|
|
{
|
|
|
|
$response = $model->toArray();
|
|
|
|
|
2021-08-07 20:25:06 +00:00
|
|
|
$response[$model->getUpdatedAtColumn()] = self::formatTimestamp($model->updated_at);
|
|
|
|
$response[$model->getCreatedAtColumn()] = self::formatTimestamp($model->created_at);
|
2018-01-27 18:38:56 +00:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include the Eggs relationship on the given Nest model transformation.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-08-07 20:25:06 +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.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-08-07 20:25:06 +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
|
|
|
}
|