2017-12-17 20:57:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Admin;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Location;
|
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 LocationTransformer extends BaseTransformer
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* List of resources that can be included.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = ['nodes', 'servers'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a generic transformed pack array.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Location $location
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Location $location): array
|
|
|
|
{
|
|
|
|
return $location->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the nodes associated with this location.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Location $location
|
|
|
|
* @return bool|\League\Fractal\Resource\Collection
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\PterodactylException
|
|
|
|
*/
|
|
|
|
public function includeServers(Location $location)
|
|
|
|
{
|
|
|
|
if (! $this->authorize('server-list')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $location->relationLoaded('servers')) {
|
|
|
|
$location->load('servers');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->collection($location->getRelation('servers'), new ServerTransformer($this->getRequest()), 'server');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the nodes associated with this location.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Location $location
|
|
|
|
* @return bool|\League\Fractal\Resource\Collection
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\PterodactylException
|
|
|
|
*/
|
|
|
|
public function includeNodes(Location $location)
|
|
|
|
{
|
|
|
|
if (! $this->authorize('node-list')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $location->relationLoaded('nodes')) {
|
|
|
|
$location->load('nodes');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->collection($location->getRelation('nodes'), new NodeTransformer($this->getRequest()), 'node');
|
|
|
|
}
|
|
|
|
}
|