ADD : utilisation des jeux depuis la bd

correction_routeur^2
Victor SOULIER 1 year ago
parent b9c6b6039a
commit 53ea6f172f

@ -8,11 +8,12 @@ use model\UserGateway;
class FrontController class FrontController
{ {
private Connection $con;
public function __construct() public function __construct()
{ {
global $twig, $router, $config; 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', '/', 'null');
$router->map('GET|POST', '/join', 'join'); $router->map('GET|POST', '/join', 'join');
@ -66,7 +67,7 @@ class FrontController
echo $twig->render('login.html'); echo $twig->render('login.html');
elseif(isset($_REQUEST['login'])) { elseif(isset($_REQUEST['login'])) {
Validation::valUserLogin($_REQUEST['login'], $dVueErreur); Validation::valUserLogin($_REQUEST['login'], $dVueErreur);
$ug = new UserGateway($con); $ug = new UserGateway($this->con);
if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { if($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login']; $_SESSION['pseudo'] = $_REQUEST['login'];
header("Location: ."); header("Location: .");
@ -106,8 +107,11 @@ class FrontController
public function CreateParty() : void public function CreateParty() : void
{ {
global $twig; global $twig;
$listJeu = (new \model\JeuGateway($this->con))->getAll();
$dVueCreate = \model\GameGateway::getGames(); $dVueCreate = [];
foreach($listJeu as $jeu){
$dVueCreate[] = ['id' => $jeu->getId(), 'nom' => $jeu->getNom()];
}
echo $twig->render('create.html', ['dVueCreate' => $dVueCreate]); echo $twig->render('create.html', ['dVueCreate' => $dVueCreate]);
} }

@ -1,15 +0,0 @@
<?php
namespace model;
class GameGateway
{
public static function getGames() : array
{
// TODO: implémenter requête SQL
return array(
0 => ["Qui-est-ce ?", "Le qui est-ce...."],
1 => ["Kahoot", "Le Kahoot permet..."]
);
}
}

@ -0,0 +1,21 @@
<?php
namespace model;
class JeuGateway
{
private $con;
function __construct(Connection $con) {
$this->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;
}
}

@ -6,18 +6,18 @@ class Jeu
{ {
private int $id; private int $id;
private string $nom; private string $nom;
private int $nbParties; private int $nbrParties;
/** /**
* @param int $id * @param int $id
* @param string $nom * @param string $nom
* @param string $nbParties * @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->id=$id;
$this->nom=$nom; $this->nom=$nom;
$this->nbParties=$nbParties; $this->nbrParties=$nbrParties;
} }
/** /**
@ -38,14 +38,14 @@ class Jeu
* @return int * @return int
*/ */
public function getNbParties():int{ public function getNbParties():int{
return $this->nbParties; return $this->nbrParties;
} }
/** /**
* @return int * @return int
*/ */
public function incrementNbParties(): int{ public function incrementNbParties(): int{
$this->nbParties += 1; $this->nbrParties += 1;
return $this->nbParties; return $this->nbrParties;
} }
} }

@ -30,8 +30,8 @@
{% if dVueCreate is defined %} {% if dVueCreate is defined %}
{% for value in dVueCreate %} {% for value in dVueCreate %}
<div> <div>
<input type="radio" name="game" id="{{value[0]}}" value="{{value[0]}}"> <input type="radio" name="jeu" id="{{value['id']}}" value="{{value[0]}}">
<label for="{{value[0]}}">{{value[0]}}</label> <label for="{{value['id']}}">{{value['nom']}}</label>
</div> </div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}

Loading…
Cancel
Save