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.
46 lines
1.2 KiB
46 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Controller\Sub;
|
|
|
|
use App\Connexion;
|
|
use App\Data\TacticInfo;
|
|
use App\Gateway\TacticInfoGateway;
|
|
use App\Http\HttpCodes;
|
|
use App\Http\HttpResponse;
|
|
use App\Http\JsonHttpResponse;
|
|
use App\Http\ViewHttpResponse;
|
|
use App\Model\TacticModel;
|
|
|
|
class EditorController {
|
|
private TacticModel $model;
|
|
|
|
public function __construct() {
|
|
$this->model = new TacticModel(new TacticInfoGateway(new Connexion(get_database())));
|
|
}
|
|
|
|
private function openEditor(TacticInfo $tactic): HttpResponse {
|
|
return ViewHttpResponse::react("views/Editor.tsx", ["name" => $tactic->getName(), "id" => $tactic->getId()]);
|
|
}
|
|
|
|
public function createNew(): HttpResponse {
|
|
$tactic = $this->model->makeNewDefault();
|
|
return $this->openEditor($tactic);
|
|
}
|
|
|
|
/**
|
|
* returns an editor view for a given tactic
|
|
* @param int $id the targeted tactic identifier
|
|
* @return HttpResponse
|
|
*/
|
|
public function edit(int $id): HttpResponse {
|
|
$tactic = $this->model->get($id);
|
|
|
|
if ($tactic == null) {
|
|
return new JsonHttpResponse("la tactique " . $id . " n'existe pas", HttpCodes::NOT_FOUND);
|
|
}
|
|
|
|
return $this->openEditor($tactic);
|
|
}
|
|
|
|
}
|