2017-07-03 02:29:58 +00:00
|
|
|
<?php
|
|
|
|
|
2017-08-19 03:19:06 +00:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2017-07-03 02:29:58 +00:00
|
|
|
|
2017-08-19 03:19:06 +00:00
|
|
|
use Pterodactyl\Models\Pack;
|
|
|
|
use Pterodactyl\Repositories\Concerns\Searchable;
|
2018-01-05 04:49:50 +00:00
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
2017-08-19 03:19:06 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
2017-07-15 16:52:34 +00:00
|
|
|
|
2017-08-19 03:19:06 +00:00
|
|
|
class PackRepository extends EloquentRepository implements PackRepositoryInterface
|
2017-07-03 02:29:58 +00:00
|
|
|
{
|
2017-08-19 03:19:06 +00:00
|
|
|
use Searchable;
|
|
|
|
|
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
|
|
|
*/
|
2017-08-19 03:19:06 +00:00
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Pack::class;
|
|
|
|
}
|
2017-07-15 16:52:34 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return a pack with the associated server models attached to it.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Pack $pack
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param bool $refresh
|
2018-01-05 04:49:50 +00:00
|
|
|
* @return \Pterodactyl\Models\Pack
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function loadServerData(Pack $pack, bool $refresh = false): Pack
|
2017-07-15 16:52:34 +00:00
|
|
|
{
|
2018-01-05 04:49:50 +00:00
|
|
|
if ($refresh) {
|
|
|
|
$pack->load(['servers.node', 'servers.user']);
|
2017-08-21 00:23:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 04:49:50 +00:00
|
|
|
$pack->loadMissing(['servers.node', 'servers.user']);
|
2017-08-21 00:23:50 +00:00
|
|
|
|
2018-01-05 04:49:50 +00:00
|
|
|
return $pack;
|
2017-08-21 00:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return a paginated listing of packs with their associated egg and server count.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
2017-08-21 00:23:50 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function paginateWithEggAndServerCount(): LengthAwarePaginator
|
2017-08-21 00:23:50 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->getBuilder()->with('egg')->withCount('servers')
|
2018-01-06 18:49:32 +00:00
|
|
|
->search($this->getSearchTerm())
|
2018-01-05 04:49:50 +00:00
|
|
|
->paginate(50, $this->getColumns());
|
2017-08-21 00:23:50 +00:00
|
|
|
}
|
2017-07-03 02:29:58 +00:00
|
|
|
}
|