misc_pterodactyl-panel/app/Transformers/Api/Client/ScheduleTransformer.php

62 lines
1.8 KiB
PHP
Raw Normal View History

2020-02-08 23:23:08 +00:00
<?php
namespace Pterodactyl\Transformers\Api\Client;
use Pterodactyl\Models\Task;
use Pterodactyl\Models\Schedule;
use League\Fractal\Resource\Collection;
2020-02-08 23:23:08 +00:00
class ScheduleTransformer extends BaseClientTransformer
{
protected array $availableIncludes = ['tasks'];
2020-02-08 23:23:08 +00:00
2022-05-04 23:35:10 +00:00
protected array $defaultIncludes = ['tasks'];
2020-02-08 23:23:08 +00:00
/**
* {@inheritdoc}
*/
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
2020-02-08 23:23:08 +00:00
{
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,
2020-02-08 23:23:08 +00:00
'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(),
2020-02-08 23:23:08 +00:00
];
}
/**
* Allows attaching the tasks specific to the schedule in the response.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeTasks(Schedule $model): Collection
2020-02-08 23:23:08 +00:00
{
return $this->collection(
2021-01-23 20:33:34 +00:00
$model->tasks,
$this->makeTransformer(TaskTransformer::class),
Task::RESOURCE_NAME
2020-02-08 23:23:08 +00:00
);
}
}