Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/ScheduleRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\Schedule;
6
use Illuminate\Support\Collection;
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
9
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
10
11
class ScheduleRepository extends EloquentRepository implements ScheduleRepositoryInterface
12
{
13
/**
14
* Return the model backing this repository.
15
*/
16
public function model(): string
17
{
18
return Schedule::class;
19
}
20
21
/**
22
* Return all the schedules for a given server.
23
*/
24
public function findServerSchedules(int $server): Collection
25
{
26
return $this->getBuilder()->withCount('tasks')->where('server_id', '=', $server)->get($this->getColumns());
27
}
28
29
/**
30
* Return a schedule model with all the associated tasks as a relationship.
31
*
32
* @throws RecordNotFoundException
33
*/
34
public function getScheduleWithTasks(int $schedule): Schedule
35
{
36
try {
37
return $this->getBuilder()->with('tasks')->findOrFail($schedule, $this->getColumns());
38
} catch (ModelNotFoundException) {
39
throw new RecordNotFoundException();
40
}
41
}
42
}
43
44