Files

81 lines
2.3 KiB
PHP
Raw Permalink Normal View History

<?php
2017-07-15 11:52:34 -05:00
namespace Pterodactyl\Repositories\Eloquent;
2017-10-06 23:57:53 -05:00
use Pterodactyl\Models\Nest;
2022-10-14 10:59:20 -06:00
use Illuminate\Database\Eloquent\Collection;
2017-10-06 23:57:53 -05:00
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
2017-08-05 17:26:30 -05:00
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
2017-07-15 11:52:34 -05:00
2017-10-06 23:57:53 -05:00
class NestRepository extends EloquentRepository implements NestRepositoryInterface
{
/**
* Return the model backing this repository.
2017-07-15 11:52:34 -05:00
*/
2022-10-14 10:59:20 -06:00
public function model(): string
2017-07-15 11:52:34 -05:00
{
2017-10-06 23:57:53 -05:00
return Nest::class;
2017-07-15 11:52:34 -05:00
}
/**
* Return a nest or all nests with their associated eggs and variables.
2017-10-03 23:31:04 -05:00
*
* @return \Illuminate\Database\Eloquent\Collection<int, \Pterodactyl\Models\Nest>|\Pterodactyl\Models\Nest
*
2024-10-21 19:18:20 -06:00
* @throws RecordNotFoundException
*/
2024-10-21 19:18:20 -06:00
public function getWithEggs(?int $id = null): Collection|Nest
2017-07-15 11:52:34 -05:00
{
$instance = $this->getBuilder()->with('eggs', 'eggs.variables');
2017-07-15 11:52:34 -05:00
2021-01-23 12:33:34 -08:00
if (!is_null($id)) {
2017-07-15 11:52:34 -05:00
$instance = $instance->find($id, $this->getColumns());
2021-01-23 12:33:34 -08:00
if (!$instance) {
throw new RecordNotFoundException();
2017-07-15 11:52:34 -05:00
}
return $instance;
}
return $instance->get($this->getColumns());
}
/**
* Return a nest or all nests and the count of eggs and servers for that nest.
2017-10-03 23:31:04 -05:00
*
* @return \Illuminate\Database\Eloquent\Collection<int, \Pterodactyl\Models\Nest>|\Pterodactyl\Models\Nest
*
2024-10-21 19:18:20 -06:00
* @throws RecordNotFoundException
*/
2024-10-21 19:18:20 -06:00
public function getWithCounts(?int $id = null): Collection|Nest
{
$instance = $this->getBuilder()->withCount(['eggs', 'servers']);
2017-10-02 22:51:13 -05:00
2021-01-23 12:33:34 -08:00
if (!is_null($id)) {
2017-10-02 22:51:13 -05:00
$instance = $instance->find($id, $this->getColumns());
2021-01-23 12:33:34 -08:00
if (!$instance) {
throw new RecordNotFoundException();
2017-10-02 22:51:13 -05:00
}
return $instance;
}
return $instance->get($this->getColumns());
}
2017-10-02 22:51:13 -05:00
/**
2017-10-06 23:57:53 -05:00
* Return a nest along with its associated eggs and the servers relation on those eggs.
2017-10-03 23:31:04 -05:00
*
2024-10-21 19:18:20 -06:00
* @throws RecordNotFoundException
2017-10-02 22:51:13 -05:00
*/
2017-10-06 23:57:53 -05:00
public function getWithEggServers(int $id): Nest
2017-10-02 22:51:13 -05:00
{
2017-10-06 23:57:53 -05:00
$instance = $this->getBuilder()->with('eggs.servers')->find($id, $this->getColumns());
2021-01-23 12:33:34 -08:00
if (!$instance) {
throw new RecordNotFoundException();
}
return $instance; // @phpstan-ignore return.type
}
}