diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index 2e39149..edb5ea6 100644 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -8,11 +8,12 @@ use model\UserGateway; class FrontController { + private Connection $con; public function __construct() { global $twig, $router, $config; - $con = new Connection($config["db"]["dsn"], $config["db"]["login"], $config["db"]["mdp"]); + $this->con = new Connection($config["db"]["dsn"], $config["db"]["login"], $config["db"]["mdp"]); $router->map('GET|POST', '/', 'null'); $router->map('GET|POST', '/join', 'join'); @@ -66,7 +67,7 @@ class FrontController echo $twig->render('login.html'); elseif(isset($_REQUEST['login'])) { Validation::valUserLogin($_REQUEST['login'], $dVueErreur); - $ug = new UserGateway($con); + $ug = new UserGateway($this->con); if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { $_SESSION['pseudo'] = $_REQUEST['login']; header("Location: ."); @@ -106,8 +107,11 @@ class FrontController public function CreateParty() : void { global $twig; - - $dVueCreate = \model\GameGateway::getGames(); + $listJeu = (new \model\JeuGateway($this->con))->getAll(); + $dVueCreate = []; + foreach($listJeu as $jeu){ + $dVueCreate[] = ['id' => $jeu->getId(), 'nom' => $jeu->getNom()]; + } echo $twig->render('create.html', ['dVueCreate' => $dVueCreate]); } diff --git a/project/src/model/gateways/GameGateway.php b/project/src/model/gateways/GameGateway.php deleted file mode 100644 index 897d5ad..0000000 --- a/project/src/model/gateways/GameGateway.php +++ /dev/null @@ -1,15 +0,0 @@ - ["Qui-est-ce ?", "Le qui est-ce...."], - 1 => ["Kahoot", "Le Kahoot permet..."] - ); - } -} \ No newline at end of file diff --git a/project/src/model/gateways/JeuGateway.php b/project/src/model/gateways/JeuGateway.php new file mode 100644 index 0000000..d1c6c92 --- /dev/null +++ b/project/src/model/gateways/JeuGateway.php @@ -0,0 +1,21 @@ +con = $con; + } + public function getAll() : array + { + $this->con->executeQuery("SELECT id, nom, nbrparties FROM Jeu;"); + $listJeu = []; + foreach($this->con->getResults() as $row){ + $listJeu[] = new Jeu($row['id'], $row['nom'], $row['nbrparties']); + } + return $listJeu; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Jeu.php b/project/src/model/metier/Jeu.php index 1d53068..89c9161 100644 --- a/project/src/model/metier/Jeu.php +++ b/project/src/model/metier/Jeu.php @@ -6,18 +6,18 @@ class Jeu { private int $id; private string $nom; - private int $nbParties; + private int $nbrParties; /** * @param int $id * @param string $nom * @param string $nbParties */ - public function __construct(int $id, string $nom, int $nbParties) + public function __construct(int $id, string $nom, int $nbrParties) { $this->id=$id; $this->nom=$nom; - $this->nbParties=$nbParties; + $this->nbrParties=$nbrParties; } /** @@ -38,14 +38,14 @@ class Jeu * @return int */ public function getNbParties():int{ - return $this->nbParties; + return $this->nbrParties; } /** * @return int */ public function incrementNbParties(): int{ - $this->nbParties += 1; - return $this->nbParties; + $this->nbrParties += 1; + return $this->nbrParties; } } \ No newline at end of file diff --git a/project/src/templates/create.html b/project/src/templates/create.html index bfb8ba3..5f61c36 100644 --- a/project/src/templates/create.html +++ b/project/src/templates/create.html @@ -30,8 +30,8 @@ {% if dVueCreate is defined %} {% for value in dVueCreate %}
- - + +
{% endfor %} {% endif %}