2020-05-21 00:00:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Mount;
|
2020-05-21 19:19:59 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2020-05-21 19:22:32 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2020-05-21 00:00:53 +00:00
|
|
|
use Pterodactyl\Repositories\Concerns\Searchable;
|
2020-05-21 01:11:20 +00:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
2020-05-21 00:00:53 +00:00
|
|
|
|
|
|
|
class MountRepository extends EloquentRepository
|
|
|
|
{
|
|
|
|
use Searchable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the model backing this repository.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Mount::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return mounts with a count of eggs, nodes, and servers attached to it.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Support\Collection
|
|
|
|
*/
|
|
|
|
public function getAllWithDetails(): Collection
|
|
|
|
{
|
|
|
|
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
|
|
|
|
}
|
2020-05-21 01:11:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all of the mounts and their respective relations.
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return mixed
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function getWithRelations(string $id): Mount
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return $this->getBuilder()->with('eggs', 'nodes')->findOrFail($id, $this->getColumns());
|
|
|
|
} catch (ModelNotFoundException $exception) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 19:19:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-05-21 20:27:23 +00:00
|
|
|
* Return mounts available to a server (ignoring if they are or are not mounted).
|
2020-05-21 19:19:59 +00:00
|
|
|
*
|
|
|
|
* @param Server $server
|
|
|
|
* @return \Illuminate\Support\Collection
|
|
|
|
*/
|
|
|
|
public function getMountListForServer(Server $server): Collection
|
|
|
|
{
|
|
|
|
return $this->getBuilder()
|
|
|
|
->whereHas('eggs', function ($q) use ($server) {
|
|
|
|
$q->where('id', '=', $server->egg_id);
|
|
|
|
})
|
|
|
|
->whereHas('nodes', function ($q) use ($server) {
|
|
|
|
$q->where('id', '=', $server->node_id);
|
|
|
|
})
|
|
|
|
->get($this->getColumns());
|
|
|
|
}
|
2020-05-21 00:00:53 +00:00
|
|
|
}
|