You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
<?php
|
|
|
|
namespace IQBall\App\Controller;
|
|
|
|
use IQBall\Core\Data\TacticInfo;
|
|
use IQBall\Core\Http\HttpCodes;
|
|
use IQBall\Core\Http\HttpResponse;
|
|
use IQBall\App\ViewHttpResponse;
|
|
use IQBall\Core\Model\TacticModel;
|
|
use IQBall\Core\Session\SessionHandle;
|
|
use IQBall\Core\Validator\TacticValidator;
|
|
|
|
class EditorController {
|
|
private TacticModel $model;
|
|
|
|
public function __construct(TacticModel $model) {
|
|
$this->model = $model;
|
|
}
|
|
|
|
private function openEditor(TacticInfo $tactic): HttpResponse {
|
|
return ViewHttpResponse::react("views/Editor.tsx", ["name" => $tactic->getName(), "id" => $tactic->getId()]);
|
|
}
|
|
|
|
public function createNew(SessionHandle $session): HttpResponse {
|
|
$tactic = $this->model->makeNewDefault($session->getAccount()->getId());
|
|
return $this->openEditor($tactic);
|
|
}
|
|
|
|
/**
|
|
* returns an editor view for a given tactic
|
|
* @param int $id the targeted tactic identifier
|
|
* @param SessionHandle $session
|
|
* @return HttpResponse
|
|
*/
|
|
public function edit(int $id, SessionHandle $session): HttpResponse {
|
|
$tactic = $this->model->get($id);
|
|
|
|
$failure = TacticValidator::validateAccess($tactic, $id, $session->getAccount()->getId());
|
|
|
|
if ($failure != null) {
|
|
return ViewHttpResponse::twig('error.html.twig', ['failures' => [$failure]], HttpCodes::NOT_FOUND);
|
|
}
|
|
|
|
return $this->openEditor($tactic);
|
|
}
|
|
|
|
|
|
}
|