Add basic listing of server schedules
This commit is contained in:
parent
f9ec96c70a
commit
32e9fb0346
21 changed files with 508 additions and 79 deletions
64
app/Transformers/Api/Client/ScheduleTransformer.php
Normal file
64
app/Transformers/Api/Client/ScheduleTransformer.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Client;
|
||||
|
||||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ScheduleTransformer extends BaseClientTransformer
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['tasks'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getResourceName(): string
|
||||
{
|
||||
return Schedule::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a transformed schedule model such that a client can view the information.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Schedule $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Schedule $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'name' => $model->name,
|
||||
'cron' => [
|
||||
'day_of_week' => $model->cron_day_of_week,
|
||||
'day_of_month' => $model->cron_day_of_month,
|
||||
'hour' => $model->cron_hour,
|
||||
'minute' => $model->cron_minute,
|
||||
],
|
||||
'is_active' => $model->is_active,
|
||||
'is_processing' => $model->is_processing,
|
||||
'last_run_at' => $model->last_run_at ? $model->last_run_at->toIso8601String() : null,
|
||||
'next_run_at' => $model->next_run_at ? $model->next_run_at->toIso8601String() : null,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'updated_at' => $model->updated_at->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows attaching the tasks specific to the schedule in the response.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Schedule $model
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeTasks(Schedule $model)
|
||||
{
|
||||
return $this->collection(
|
||||
$model->tasks, $this->makeTransformer(TaskTransformer::class), Task::RESOURCE_NAME
|
||||
);
|
||||
}
|
||||
}
|
36
app/Transformers/Api/Client/TaskTransformer.php
Normal file
36
app/Transformers/Api/Client/TaskTransformer.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Client;
|
||||
|
||||
use Pterodactyl\Models\Task;
|
||||
|
||||
class TaskTransformer extends BaseClientTransformer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getResourceName(): string
|
||||
{
|
||||
return Task::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a schedule's task into a client viewable format.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Task $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Task $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'sequence_id' => $model->sequence_id,
|
||||
'action' => $model->action,
|
||||
'payload' => $model->payload,
|
||||
'time_offset' => $model->time_offset,
|
||||
'is_queued' => $model->is_queued,
|
||||
'created_at' => $model->created_at->toIso8601String(),
|
||||
'updated_at' => $model->updated_at->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue