2017-07-03 02:29:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Location;
|
2018-01-05 04:49:50 +00:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2017-07-03 02:29:58 +00:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
|
|
|
|
2017-08-19 03:19:06 +00:00
|
|
|
class LocationRepository extends EloquentRepository implements LocationRepositoryInterface
|
2017-07-03 02:29:58 +00:00
|
|
|
{
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return the model backing this repository.
|
|
|
|
*
|
|
|
|
* @return string
|
2017-07-03 02:29:58 +00:00
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Location::class;
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:51:18 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return locations with a count of nodes and servers attached to it.
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function getAllWithDetails(): Collection
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->withCount('nodes', 'servers')->get($this->getColumns());
|
|
|
|
}
|
|
|
|
|
2017-08-09 04:24:55 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return all of the available locations with the nodes as a relationship.
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function getAllWithNodes(): Collection
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->with('nodes')->get($this->getColumns());
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:51:18 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return all of the nodes and their respective count of servers for a location.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function getWithNodes(int $id): Location
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
2018-01-05 04:49:50 +00:00
|
|
|
try {
|
|
|
|
return $this->getBuilder()->with('nodes.servers')->findOrFail($id, $this->getColumns());
|
|
|
|
} catch (ModelNotFoundException $exception) {
|
2021-01-23 20:33:34 +00:00
|
|
|
throw new RecordNotFoundException();
|
2017-09-15 05:16:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-23 19:51:18 +00:00
|
|
|
|
2017-09-15 05:16:03 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return a location and the count of nodes in that location.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-09-15 05:16:03 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function getWithNodeCount(int $id): Location
|
2017-09-15 05:16:03 +00:00
|
|
|
{
|
2018-01-05 04:49:50 +00:00
|
|
|
try {
|
|
|
|
return $this->getBuilder()->withCount('nodes')->findOrFail($id, $this->getColumns());
|
|
|
|
} catch (ModelNotFoundException $exception) {
|
2021-01-23 20:33:34 +00:00
|
|
|
throw new RecordNotFoundException();
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 02:29:58 +00:00
|
|
|
}
|