Files

43 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2017-09-09 23:55:21 -05:00
<?php
namespace Pterodactyl\Repositories\Eloquent;
2017-09-09 23:55:21 -05:00
use Pterodactyl\Models\Schedule;
2017-10-27 21:42:53 -05:00
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
2017-10-27 21:42:53 -05:00
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
2017-09-09 23:55:21 -05:00
class ScheduleRepository extends EloquentRepository implements ScheduleRepositoryInterface
2017-09-09 23:55:21 -05:00
{
/**
* Return the model backing this repository.
*/
2022-10-14 10:59:20 -06:00
public function model(): string
{
return Schedule::class;
}
2017-09-09 23:55:21 -05:00
/**
2022-10-14 10:59:20 -06:00
* Return all the schedules for a given server.
*/
2017-10-27 21:42:53 -05:00
public function findServerSchedules(int $server): Collection
{
return $this->getBuilder()->withCount('tasks')->where('server_id', '=', $server)->get($this->getColumns());
2017-09-09 23:55:21 -05:00
}
/**
2022-10-14 10:59:20 -06:00
* Return a schedule model with all the associated tasks as a relationship.
2017-10-27 21:42:53 -05:00
*
2024-10-21 19:18:20 -06:00
* @throws RecordNotFoundException
*/
2017-10-27 21:42:53 -05:00
public function getScheduleWithTasks(int $schedule): Schedule
2017-09-09 23:55:21 -05:00
{
try {
return $this->getBuilder()->with('tasks')->findOrFail($schedule, $this->getColumns());
2022-10-14 10:59:20 -06:00
} catch (ModelNotFoundException) {
2021-01-23 12:33:34 -08:00
throw new RecordNotFoundException();
2017-10-27 21:42:53 -05:00
}
2017-09-09 23:55:21 -05:00
}
}