Add basic listing of server schedules

This commit is contained in:
Dane Everitt 2020-02-08 15:23:08 -08:00
parent f9ec96c70a
commit 32e9fb0346
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
21 changed files with 508 additions and 79 deletions

View 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
);
}
}

View 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(),
];
}
}