2017-10-07 04:57:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Nests;
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
use Javascript;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Illuminate\View\View;
|
|
|
|
use Pterodactyl\Models\Egg;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Pterodactyl\Services\Eggs\EggUpdateService;
|
|
|
|
use Pterodactyl\Services\Eggs\EggCreationService;
|
|
|
|
use Pterodactyl\Services\Eggs\EggDeletionService;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-10-07 04:57:53 +00:00
|
|
|
|
|
|
|
class EggController extends Controller
|
|
|
|
{
|
2017-10-07 21:16:51 +00:00
|
|
|
protected $alert;
|
2019-09-06 04:32:57 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
protected $creationService;
|
2019-09-06 04:32:57 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
protected $deletionService;
|
2019-09-06 04:32:57 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
protected $nestRepository;
|
2019-09-06 04:32:57 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
protected $repository;
|
2019-09-06 04:32:57 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
protected $updateService;
|
2017-10-07 04:57:53 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
|
|
|
EggCreationService $creationService,
|
|
|
|
EggDeletionService $deletionService,
|
|
|
|
EggRepositoryInterface $repository,
|
|
|
|
EggUpdateService $updateService,
|
|
|
|
NestRepositoryInterface $nestRepository
|
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
|
|
|
$this->creationService = $creationService;
|
|
|
|
$this->deletionService = $deletionService;
|
|
|
|
$this->nestRepository = $nestRepository;
|
2017-10-07 04:57:53 +00:00
|
|
|
$this->repository = $repository;
|
2017-10-07 21:16:51 +00:00
|
|
|
$this->updateService = $updateService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a request to display the Egg creation page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function create(): View
|
|
|
|
{
|
|
|
|
$nests = $this->nestRepository->getWithEggs();
|
|
|
|
Javascript::put(['nests' => $nests->keyBy('id')]);
|
|
|
|
|
|
|
|
return view('admin.eggs.new', ['nests' => $nests]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to store a new Egg.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
|
|
|
*/
|
|
|
|
public function store(EggFormRequest $request): RedirectResponse
|
|
|
|
{
|
|
|
|
$egg = $this->creationService->handle($request->normalize());
|
|
|
|
$this->alert->success(trans('admin/nests.eggs.notices.egg_created'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.egg.view', $egg->id);
|
2017-10-07 04:57:53 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
/**
|
|
|
|
* Handle request to view a single Egg.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Egg $egg
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function view(Egg $egg): View
|
|
|
|
{
|
2017-10-07 21:16:51 +00:00
|
|
|
return view('admin.eggs.view', ['egg' => $egg]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to update an Egg.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest $request
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Models\Egg $egg
|
2017-10-07 21:16:51 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
|
|
|
*/
|
|
|
|
public function update(EggFormRequest $request, Egg $egg): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->updateService->handle($egg, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/nests.eggs.notices.updated'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.egg.view', $egg->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to destroy an egg.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Egg $egg
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
|
|
|
*/
|
|
|
|
public function destroy(Egg $egg): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->deletionService->handle($egg->id);
|
|
|
|
$this->alert->success(trans('admin/nests.eggs.notices.deleted'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.view', $egg->nest_id);
|
2017-10-07 04:57:53 +00:00
|
|
|
}
|
|
|
|
}
|