2017-07-03 04:29:58 +02:00
|
|
|
<?php
|
2017-09-26 04:43:01 +02:00
|
|
|
/**
|
2017-07-03 04:29:58 +02:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 04:43:01 +02:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-07-03 04:29:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Location;
|
2017-08-27 21:55:25 +02:00
|
|
|
use Pterodactyl\Repositories\Concerns\Searchable;
|
2017-07-03 04:29:58 +02:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
|
|
|
|
2017-08-19 05:19:06 +02:00
|
|
|
class LocationRepository extends EloquentRepository implements LocationRepositoryInterface
|
2017-07-03 04:29:58 +02:00
|
|
|
{
|
2017-08-19 05:19:06 +02:00
|
|
|
use Searchable;
|
|
|
|
|
2017-07-03 04:29:58 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $searchTerm;
|
|
|
|
|
|
|
|
/**
|
2017-07-08 21:07:51 +02:00
|
|
|
* {@inheritdoc}
|
2017-07-03 04:29:58 +02:00
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Location::class;
|
|
|
|
}
|
|
|
|
|
2017-07-23 21:51:18 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-08-09 06:24:55 +02:00
|
|
|
public function getAllWithDetails()
|
2017-07-23 21:51:18 +02:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->withCount('nodes', 'servers')->get($this->getColumns());
|
|
|
|
}
|
|
|
|
|
2017-08-09 06:24:55 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getAllWithNodes()
|
|
|
|
{
|
|
|
|
return $this->getBuilder()->with('nodes')->get($this->getColumns());
|
|
|
|
}
|
|
|
|
|
2017-07-23 21:51:18 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithNodes($id)
|
|
|
|
{
|
|
|
|
$instance = $this->getBuilder()->with('nodes.servers')->find($id, $this->getColumns());
|
2017-09-15 07:16:03 +02:00
|
|
|
if (! $instance) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2017-07-23 21:51:18 +02:00
|
|
|
|
2017-09-15 07:16:03 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getWithNodeCount($id)
|
|
|
|
{
|
|
|
|
$instance = $this->getBuilder()->withCount('nodes')->find($id, $this->getColumns());
|
2017-07-23 21:51:18 +02:00
|
|
|
if (! $instance) {
|
2017-09-15 07:16:03 +02:00
|
|
|
throw new RecordNotFoundException;
|
2017-07-23 21:51:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2017-07-03 04:29:58 +02:00
|
|
|
}
|