2017-07-03 03:29:58 +01:00
|
|
|
<?php
|
2017-09-26 03:43:01 +01:00
|
|
|
/**
|
2017-07-03 03:29:58 +01:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 03:43:01 +01:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-07-03 03:29:58 +01:00
|
|
|
*/
|
|
|
|
|
2017-07-15 17:52:34 +01:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2017-07-03 03:29:58 +01:00
|
|
|
|
2017-07-15 17:52:34 +01:00
|
|
|
use Pterodactyl\Models\Service;
|
2017-08-05 23:26:30 +01:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
2017-07-15 17:52:34 +01:00
|
|
|
|
|
|
|
class ServiceRepository extends EloquentRepository implements ServiceRepositoryInterface
|
2017-07-03 03:29:58 +01:00
|
|
|
{
|
2017-07-08 20:07:51 +01:00
|
|
|
/**
|
2017-07-15 17:52:34 +01:00
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Service::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-04 05:31:04 +01:00
|
|
|
* Return a service or all services with their associated options, variables, and packs.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Service
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-07-08 20:07:51 +01:00
|
|
|
*/
|
2017-10-04 05:31:04 +01:00
|
|
|
public function getWithOptions(int $id = null)
|
2017-07-15 17:52:34 +01:00
|
|
|
{
|
|
|
|
$instance = $this->getBuilder()->with('options.packs', 'options.variables');
|
|
|
|
|
|
|
|
if (! is_null($id)) {
|
|
|
|
$instance = $instance->find($id, $this->getColumns());
|
|
|
|
if (! $instance) {
|
2017-10-03 04:51:13 +01:00
|
|
|
throw new RecordNotFoundException;
|
2017-07-15 17:52:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance->get($this->getColumns());
|
|
|
|
}
|
2017-08-16 04:21:47 +01:00
|
|
|
|
|
|
|
/**
|
2017-10-04 05:31:04 +01:00
|
|
|
* Return a service or all services and the count of options, packs, and servers for that service.
|
|
|
|
*
|
|
|
|
* @param int|null $id
|
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Service
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-08-16 04:21:47 +01:00
|
|
|
*/
|
2017-10-04 05:31:04 +01:00
|
|
|
public function getWithCounts(int $id = null)
|
2017-08-16 04:21:47 +01:00
|
|
|
{
|
2017-10-03 04:51:13 +01:00
|
|
|
$instance = $this->getBuilder()->withCount(['options', 'packs', 'servers']);
|
|
|
|
|
|
|
|
if (! is_null($id)) {
|
|
|
|
$instance = $instance->find($id, $this->getColumns());
|
|
|
|
if (! $instance) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance->get($this->getColumns());
|
|
|
|
}
|
2017-08-16 04:21:47 +01:00
|
|
|
|
2017-10-03 04:51:13 +01:00
|
|
|
/**
|
2017-10-04 05:31:04 +01:00
|
|
|
* Return a service along with its associated options and the servers relation on those options.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Pterodactyl\Models\Service
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-10-03 04:51:13 +01:00
|
|
|
*/
|
|
|
|
public function getWithOptionServers(int $id): Service
|
|
|
|
{
|
2017-08-16 04:21:47 +01:00
|
|
|
$instance = $this->getBuilder()->with('options.servers')->find($id, $this->getColumns());
|
|
|
|
if (! $instance) {
|
2017-10-03 04:51:13 +01:00
|
|
|
throw new RecordNotFoundException;
|
2017-08-16 04:21:47 +01:00
|
|
|
}
|
|
|
|
|
2017-10-03 04:51:13 +01:00
|
|
|
/* @var Service $instance */
|
2017-08-16 04:21:47 +01:00
|
|
|
return $instance;
|
|
|
|
}
|
2017-07-03 03:29:58 +01:00
|
|
|
}
|