Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Transformers/Api/Client/ScheduleTransformer.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Transformers\Api\Client;
4
5
use Pterodactyl\Models\Task;
6
use Pterodactyl\Models\Schedule;
7
use League\Fractal\Resource\Collection;
8
9
class ScheduleTransformer extends BaseClientTransformer
10
{
11
protected array $availableIncludes = ['tasks'];
12
13
protected array $defaultIncludes = ['tasks'];
14
15
public function getResourceName(): string
16
{
17
return Schedule::RESOURCE_NAME;
18
}
19
20
/**
21
* Returns a transformed schedule model such that a client can view the information.
22
*/
23
public function transform(Schedule $model): array
24
{
25
return [
26
'id' => $model->id,
27
'name' => $model->name,
28
'cron' => [
29
'day_of_week' => $model->cron_day_of_week,
30
'day_of_month' => $model->cron_day_of_month,
31
'month' => $model->cron_month,
32
'hour' => $model->cron_hour,
33
'minute' => $model->cron_minute,
34
],
35
'is_active' => $model->is_active,
36
'is_processing' => $model->is_processing,
37
'only_when_online' => $model->only_when_online,
38
'last_run_at' => $model->last_run_at?->toAtomString(),
39
'next_run_at' => $model->next_run_at?->toAtomString(),
40
'created_at' => $model->created_at->toAtomString(),
41
'updated_at' => $model->updated_at->toAtomString(),
42
];
43
}
44
45
/**
46
* Allows attaching the tasks specific to the schedule in the response.
47
*
48
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
49
*/
50
public function includeTasks(Schedule $model): Collection
51
{
52
return $this->collection(
53
$model->tasks,
54
$this->makeTransformer(TaskTransformer::class),
55
Task::RESOURCE_NAME
56
);
57
}
58
}
59
60