forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduleTransformer.php
More file actions
58 lines (51 loc) · 1.79 KB
/
ScheduleTransformer.php
File metadata and controls
58 lines (51 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Pterodactyl\Transformers\Api\Client;
use Pterodactyl\Models\Task;
use Pterodactyl\Models\Schedule;
use League\Fractal\Resource\Collection;
class ScheduleTransformer extends BaseClientTransformer
{
protected array $availableIncludes = ['tasks'];
protected array $defaultIncludes = ['tasks'];
public function getResourceName(): string
{
return Schedule::RESOURCE_NAME;
}
/**
* Returns a transformed schedule model such that a client can view the information.
*/
public function transform(Schedule $model): array
{
return [
'id' => $model->id,
'name' => $model->name,
'cron' => [
'day_of_week' => $model->cron_day_of_week,
'day_of_month' => $model->cron_day_of_month,
'month' => $model->cron_month,
'hour' => $model->cron_hour,
'minute' => $model->cron_minute,
],
'is_active' => $model->is_active,
'is_processing' => $model->is_processing,
'only_when_online' => $model->only_when_online,
'last_run_at' => $model->last_run_at?->toAtomString(),
'next_run_at' => $model->next_run_at?->toAtomString(),
'created_at' => $model->created_at->toAtomString(),
'updated_at' => $model->updated_at->toAtomString(),
];
}
/**
* Allows attaching the tasks specific to the schedule in the response.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeTasks(Schedule $model): Collection
{
return $this->collection(
$model->tasks,
$this->makeTransformer(TaskTransformer::class),
Task::RESOURCE_NAME
);
}
}