2019-03-24 00:47:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2019-09-06 04:41:20 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
2019-03-24 00:47:20 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Client\AllocationTransformer;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\Network\GetNetworkRequest;
|
|
|
|
|
|
|
|
class NetworkController extends ClientApiController
|
|
|
|
{
|
|
|
|
/**
|
2019-09-06 04:41:20 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\AllocationRepository
|
2019-03-24 00:47:20 +00:00
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NetworkController constructor.
|
|
|
|
*
|
2019-09-06 04:41:20 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $repository
|
2019-03-24 00:47:20 +00:00
|
|
|
*/
|
2019-09-06 04:41:20 +00:00
|
|
|
public function __construct(AllocationRepository $repository)
|
2019-03-24 00:47:20 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all of the allocations available to a server and wether or
|
|
|
|
* not they are currently assigned as the primary for this server.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Network\GetNetworkRequest $request
|
2019-09-06 04:41:20 +00:00
|
|
|
* @param \Pterodactyl\Models\Server $server
|
2019-03-24 00:47:20 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-09-06 04:41:20 +00:00
|
|
|
public function index(GetNetworkRequest $request, Server $server): array
|
2019-03-24 00:47:20 +00:00
|
|
|
{
|
|
|
|
$allocations = $this->repository->findWhere([
|
|
|
|
['server_id', '=', $server->id],
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->fractal->collection($allocations)
|
|
|
|
->transformWith($this->getTransformer(AllocationTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|