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