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
{
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]);
}

@ -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 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;
}
}

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

Loading…
Cancel
Save