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
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Location;
|
2017-08-27 20:55:25 +01:00
|
|
|
use Pterodactyl\Repositories\Concerns\Searchable;
|
2017-07-03 03:29:58 +01:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
|
|
|
|
2017-08-19 04:19:06 +01:00
|
|
|
class LocationRepository extends EloquentRepository implements LocationRepositoryInterface
|
2017-07-03 03:29:58 +01:00
|
|
|
{
|
2017-08-19 04:19:06 +01:00
|
|
|
use Searchable;
|
|
|
|
|
2017-07-03 03:29:58 +01:00
|
|
|
/**
|
2017-07-08 20:07:51 +01:00
|
|
|
* {@inheritdoc}
|
2017-07-03 03:29:58 +01:00
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Location::class;
|
|
|
|
}
|
|
|
|
|
2017-07-23 20:51:18 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-08-09 05:24:55 +01:00
|
|
|
public function getAllWithDetails()
|
2017-07-23 20:51:18 +01:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->withCount('nodes', 'servers')->get($this->getColumns());
|
|
|
|
}
|
|
|
|
|
2017-08-09 05:24:55 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getAllWithNodes()
|
|
|
|
{
|
|
|
|
return $this->getBuilder()->with('nodes')->get($this->getColumns());
|
|
|
|
}
|
|
|
|
|
2017-07-23 20:51:18 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithNodes($id)
|
|
|
|
{
|
|
|
|
$instance = $this->getBuilder()->with('nodes.servers')->find($id, $this->getColumns());
|
2017-09-15 06:16:03 +01:00
|
|
|
if (! $instance) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2017-07-23 20:51:18 +01:00
|
|
|
|
2017-09-15 06:16:03 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithNodeCount($id)
|
|
|
|
{
|
|
|
|
$instance = $this->getBuilder()->withCount('nodes')->find($id, $this->getColumns());
|
2017-07-23 20:51:18 +01:00
|
|
|
if (! $instance) {
|
2017-09-15 06:16:03 +01:00
|
|
|
throw new RecordNotFoundException;
|
2017-07-23 20:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2017-07-03 03:29:58 +01:00
|
|
|
}
|