mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-26 02:52:30 +01:00
cbcf62086f
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
use Pterodactyl\Models\Location;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
|
|
|
class LocationRepository extends EloquentRepository implements LocationRepositoryInterface
|
|
{
|
|
/**
|
|
* Return the model backing this repository.
|
|
*/
|
|
public function model(): string
|
|
{
|
|
return Location::class;
|
|
}
|
|
|
|
/**
|
|
* Return locations with a count of nodes and servers attached to it.
|
|
*/
|
|
public function getAllWithDetails(): Collection
|
|
{
|
|
return $this->getBuilder()->withCount('nodes', 'servers')->get($this->getColumns());
|
|
}
|
|
|
|
/**
|
|
* Return all the available locations with the nodes as a relationship.
|
|
*/
|
|
public function getAllWithNodes(): Collection
|
|
{
|
|
return $this->getBuilder()->with('nodes')->get($this->getColumns());
|
|
}
|
|
|
|
/**
|
|
* Return all the nodes and their respective count of servers for a location.
|
|
*
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
*/
|
|
public function getWithNodes(int $id): Location
|
|
{
|
|
try {
|
|
return $this->getBuilder()->with('nodes.servers')->findOrFail($id, $this->getColumns());
|
|
} catch (ModelNotFoundException) {
|
|
throw new RecordNotFoundException();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return a location and the count of nodes in that location.
|
|
*
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
*/
|
|
public function getWithNodeCount(int $id): Location
|
|
{
|
|
try {
|
|
return $this->getBuilder()->withCount('nodes')->findOrFail($id, $this->getColumns());
|
|
} catch (ModelNotFoundException) {
|
|
throw new RecordNotFoundException();
|
|
}
|
|
}
|
|
}
|