2020-02-08 23:23:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Pterodactyl\Models\Server;
|
2020-03-18 06:33:53 +00:00
|
|
|
use Pterodactyl\Models\Schedule;
|
2020-02-08 23:23:08 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Client\ScheduleTransformer;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
2020-03-18 06:33:53 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
2020-02-08 23:23:08 +00:00
|
|
|
|
|
|
|
class ScheduleController extends ClientApiController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns all of the schedules belonging to a given server.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function index(Request $request, Server $server)
|
|
|
|
{
|
|
|
|
$schedules = $server->schedule;
|
|
|
|
$schedules->loadMissing('tasks');
|
|
|
|
|
|
|
|
return $this->fractal->collection($schedules)
|
|
|
|
->transformWith($this->getTransformer(ScheduleTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
2020-03-18 06:33:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a specific schedule for the server.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @param \Pterodactyl\Models\Schedule $schedule
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function view(Request $request, Server $server, Schedule $schedule)
|
|
|
|
{
|
|
|
|
if ($schedule->server_id !== $server->id) {
|
|
|
|
throw new NotFoundHttpException;
|
|
|
|
}
|
|
|
|
|
|
|
|
$schedule->loadMissing('tasks');
|
|
|
|
|
|
|
|
return $this->fractal->item($schedule)
|
|
|
|
->transformWith($this->getTransformer(ScheduleTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
2020-02-08 23:23:08 +00:00
|
|
|
}
|