2020-02-08 23:23:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Schedule;
|
2022-10-14 16:59:20 +00:00
|
|
|
use League\Fractal\Resource\Collection;
|
2022-12-15 00:05:46 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2020-02-08 23:23:08 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
class ScheduleTransformer extends Transformer
|
2020-02-08 23:23:08 +00:00
|
|
|
{
|
2022-05-04 23:11:42 +00:00
|
|
|
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-03-22 20:57:31 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
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,
|
2021-01-17 03:07:39 +00:00
|
|
|
'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,
|
2021-05-01 17:44:40 +00:00
|
|
|
'only_when_online' => $model->only_when_online,
|
2022-12-15 00:05:46 +00:00
|
|
|
'last_run_at' => self::formatTimestamp($model->last_run_at),
|
|
|
|
'next_run_at' => self::formatTimestamp($model->next_run_at),
|
|
|
|
'created_at' => self::formatTimestamp($model->created_at),
|
|
|
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
2020-02-08 23:23:08 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows attaching the tasks specific to the schedule in the response.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function includeTasks(Schedule $model): Collection
|
2020-02-08 23:23:08 +00:00
|
|
|
{
|
2022-12-15 00:05:46 +00:00
|
|
|
return $this->collection($model->tasks, new TaskTransformer());
|
2020-02-08 23:23:08 +00:00
|
|
|
}
|
|
|
|
}
|