2017-12-17 20:57:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Admin;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Allocation;
|
2018-01-12 04:49:46 +00:00
|
|
|
use Pterodactyl\Transformers\Api\BaseTransformer;
|
2017-12-17 20:57:05 +00:00
|
|
|
|
2018-01-12 04:49:46 +00:00
|
|
|
class AllocationTransformer extends BaseTransformer
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
2018-01-11 05:19:03 +00:00
|
|
|
/**
|
|
|
|
* Relationships that can be loaded onto allocation transformations.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
|
|
|
'node',
|
|
|
|
'server',
|
|
|
|
];
|
|
|
|
|
2017-12-17 20:57:05 +00:00
|
|
|
/**
|
|
|
|
* Return a generic transformed allocation array.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Allocation $allocation
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Allocation $allocation)
|
|
|
|
{
|
2018-01-11 05:19:03 +00:00
|
|
|
return [
|
|
|
|
'id' => $allocation->id,
|
|
|
|
'ip' => $allocation->ip,
|
|
|
|
'alias' => $allocation->ip_alias,
|
|
|
|
'port' => $allocation->port,
|
|
|
|
'assigned' => ! is_null($allocation->server_id),
|
|
|
|
];
|
2017-12-17 20:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-11 05:19:03 +00:00
|
|
|
* Load the node relationship onto a given transformation.
|
2017-12-17 20:57:05 +00:00
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Allocation $allocation
|
2018-01-11 05:19:03 +00:00
|
|
|
* @return bool|\League\Fractal\Resource\Item
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\PterodactylException
|
|
|
|
*/
|
|
|
|
public function includeNode(Allocation $allocation)
|
|
|
|
{
|
|
|
|
if (! $this->authorize('node-view')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$allocation->loadMissing('node');
|
|
|
|
|
|
|
|
return $this->item($allocation->getRelation('node'), new NodeTransformer($this->getRequest()), 'node');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the server relationship onto a given transformation.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Allocation $allocation
|
|
|
|
* @return bool|\League\Fractal\Resource\Item
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\PterodactylException
|
2017-12-17 20:57:05 +00:00
|
|
|
*/
|
2018-01-11 05:19:03 +00:00
|
|
|
public function includeServer(Allocation $allocation)
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
2018-01-11 05:19:03 +00:00
|
|
|
if (! $this->authorize('server-view')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$allocation->loadMissing('server');
|
|
|
|
|
|
|
|
return $this->item($allocation->getRelation('server'), new ServerTransformer($this->getRequest()), 'server');
|
2017-12-17 20:57:05 +00:00
|
|
|
}
|
|
|
|
}
|