FIX: Ajout de la gestion d'erreur d'addScientifiqueDecouvert()

php
Tom 1 year ago
parent a32abbff13
commit a90f6299dc

@ -2,6 +2,7 @@
namespace controller; namespace controller;
use Exception;
use model\ConfigurationJeu; use model\ConfigurationJeu;
use model\Joueur; use model\Joueur;
use model\MdlPendu; use model\MdlPendu;
@ -10,12 +11,19 @@ use config\Validation;
use model\MdlUser; use model\MdlUser;
use model\Utilisateur; use model\Utilisateur;
use model\ValidationException; use model\ValidationException;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
class PenduController{ class PenduController{
private array $dVue; private array $dVue;
private Joueur $role; private Joueur $role;
private array $dVueErreur; private array $dVueErreur;
private MdlPendu $pendu; private MdlPendu $pendu;
/**
* @throws Exception
*/
public function __construct(Joueur $role, ConfigurationJeu $configJeu) public function __construct(Joueur $role, ConfigurationJeu $configJeu)
{ {
$this->role=$role; $this->role=$role;
@ -44,6 +52,9 @@ class PenduController{
} }
} }
/**
* @throws Exception
*/
private function reinit(){ private function reinit(){
$mdlScientifique = new MdlScientifique(); $mdlScientifique = new MdlScientifique();
$scientifique = $mdlScientifique->getRandom(); $scientifique = $mdlScientifique->getRandom();
@ -51,6 +62,11 @@ class PenduController{
$_SESSION['pendu'] = $this->pendu; $_SESSION['pendu'] = $this->pendu;
} }
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
private function renderJeu(){ private function renderJeu(){
global $twig, $config; global $twig, $config;
$this->dVue['decouvert'] = $this->pendu->getDecouvert(); $this->dVue['decouvert'] = $this->pendu->getDecouvert();
@ -63,21 +79,41 @@ class PenduController{
private function ajouterScientifiqueDecouvert(){ private function ajouterScientifiqueDecouvert(){
if($this->role instanceof Utilisateur){ if($this->role instanceof Utilisateur){
try{
(new MdlUser())->addScientifiqueDecouvert($this->role->getId(), $this->pendu->getScientifique()->getId()); (new MdlUser())->addScientifiqueDecouvert($this->role->getId(), $this->pendu->getScientifique()->getId());
} }
catch(ValidationException $e){
$this->dVueErreur[] = $e->getMessage();
}
}
} }
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
private function renderAgagne(){ private function renderAgagne(){
$this->dVue['messageScore'] = "Vous avez gagné !"; $this->dVue['messageScore'] = "Vous avez gagné !";
$this->ajouterScientifiqueDecouvert(); $this->ajouterScientifiqueDecouvert();
$this->renderScore(); $this->renderScore();
} }
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
private function renderAPerdu(){ private function renderAPerdu(){
$this->dVue['messageScore'] = "Vous avez perdu !"; $this->dVue['messageScore'] = "Vous avez perdu !";
$this->renderScore(); $this->renderScore();
} }
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
private function renderScore(){ private function renderScore(){
global $twig, $config; global $twig, $config;
$this->dVue['nbTours'] = $this->pendu->getNbTours(); $this->dVue['nbTours'] = $this->pendu->getNbTours();

Loading…
Cancel
Save