2017-07-03 02:29:58 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-07-03 02:29:58 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-07-03 02:29:58 +00:00
|
|
|
*/
|
|
|
|
|
2017-07-15 16:52:34 +00:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2017-07-03 02:29:58 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Models\Nest;
|
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
2017-07-15 16:52:34 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
class NestRepository extends EloquentRepository implements NestRepositoryInterface
|
2017-07-03 02:29:58 +00:00
|
|
|
{
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return the model backing this repository.
|
|
|
|
*
|
|
|
|
* @return string
|
2017-07-15 16:52:34 +00:00
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return Nest::class;
|
2017-07-15 16:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-13 18:13:37 +00:00
|
|
|
* Return a nest or all nests with their associated eggs and variables.
|
2017-10-04 04:31:04 +00:00
|
|
|
*
|
2021-01-03 23:25:32 +00:00
|
|
|
* @param int|null $id
|
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Nest
|
2017-10-04 04:31:04 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function getWithEggs(int $id = null)
|
2017-07-15 16:52:34 +00:00
|
|
|
{
|
2020-09-13 18:13:37 +00:00
|
|
|
$instance = $this->getBuilder()->with('eggs', 'eggs.variables');
|
2017-07-15 16:52:34 +00:00
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!is_null($id)) {
|
2017-07-15 16:52:34 +00:00
|
|
|
$instance = $instance->find($id, $this->getColumns());
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$instance) {
|
|
|
|
throw new RecordNotFoundException();
|
2017-07-15 16:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance->get($this->getColumns());
|
|
|
|
}
|
2017-08-16 03:21:47 +00:00
|
|
|
|
|
|
|
/**
|
2020-09-13 18:13:37 +00:00
|
|
|
* Return a nest or all nests and the count of eggs and servers for that nest.
|
2017-10-04 04:31:04 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @return \Pterodactyl\Models\Nest|\Illuminate\Database\Eloquent\Collection
|
2017-10-04 04:31:04 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
2017-10-04 04:31:04 +00:00
|
|
|
public function getWithCounts(int $id = null)
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
2020-09-13 18:13:37 +00:00
|
|
|
$instance = $this->getBuilder()->withCount(['eggs', 'servers']);
|
2017-10-03 03:51:13 +00:00
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!is_null($id)) {
|
2017-10-03 03:51:13 +00:00
|
|
|
$instance = $instance->find($id, $this->getColumns());
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$instance) {
|
|
|
|
throw new RecordNotFoundException();
|
2017-10-03 03:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance->get($this->getColumns());
|
|
|
|
}
|
2017-08-16 03:21:47 +00:00
|
|
|
|
2017-10-03 03:51:13 +00:00
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Return a nest along with its associated eggs and the servers relation on those eggs.
|
2017-10-04 04:31:04 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-10-03 03:51:13 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function getWithEggServers(int $id): Nest
|
2017-10-03 03:51:13 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
$instance = $this->getBuilder()->with('eggs.servers')->find($id, $this->getColumns());
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$instance) {
|
|
|
|
throw new RecordNotFoundException();
|
2017-08-16 03:21:47 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
/* @var Nest $instance */
|
2017-08-16 03:21:47 +00:00
|
|
|
return $instance;
|
|
|
|
}
|
2017-07-03 02:29:58 +00:00
|
|
|
}
|