Création de factory pour les

classes métiers Enigme et
Partie, la Factory d'
Enigme est souvent utilisée pour créer des parties
et la factory de partie sera
utile pour faire l'
historique des parties
plus tard
ServeurDeTest
Johan LACHENAL 2 years ago
parent 48b0ad212d
commit 00257a2ba4

@ -1,5 +1,5 @@
<?php <?php
include_once "../Factory/EnigmeFactory.php";
class EnigmeGateway class EnigmeGateway
{ {
private Connection $con; private Connection $con;
@ -23,7 +23,7 @@ class EnigmeGateway
public function insert(Enigme $enigme) public function insert(Enigme $enigme)
{ {
$query = "INSERT INTO Enigme VALUES (:id,:admin,:enonce,:aide,:rappel,:solution,:test,:tempsDeResolution)"; $query = "INSERT INTO Enigme VALUES (:id,:admin,:enonce,:aide,:rappel,:solution,:test,:tempsDeResolution,:points)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':id' => array($enigme->getIdEnigme(), PDO::PARAM_STR), ':id' => array($enigme->getIdEnigme(), PDO::PARAM_STR),
':admin' => array($enigme->getAdmin(), PDO::PARAM_STR), ':admin' => array($enigme->getAdmin(), PDO::PARAM_STR),
@ -32,7 +32,8 @@ class EnigmeGateway
':rappel' => array($enigme->getRappel(), PDO::PARAM_STR), ':rappel' => array($enigme->getRappel(), PDO::PARAM_STR),
':solution' => array($enigme->getSolution(), PDO::PARAM_STR), ':solution' => array($enigme->getSolution(), PDO::PARAM_STR),
':test' => array($enigme->getTest(), PDO::PARAM_STR), ':test' => array($enigme->getTest(), PDO::PARAM_STR),
':tempsDeResolution' => array($enigme->getTempsDeResolution(), PDO::PARAM_INT) ':tempsDeResolution' => array($enigme->getTempsDeResolution(), PDO::PARAM_INT),
':points' => array($enigme->getPoints(), PDO::PARAM_INT)
)); ));
} }
@ -44,19 +45,24 @@ class EnigmeGateway
)); ));
} }
public function findById(string $idEnigme) public function findById(string $idEnigme) : array
{ {
$query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme"; $query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme";
$this->con->executequery($query,array( $this->con->executequery($query,array(
':idEnigme' => array($idEnigme,PDO::PARAM_STR) ':idEnigme' => array($idEnigme,PDO::PARAM_STR)
)); ));
$results=$this->con->getResults(); $results=$this->con->getResults();
$tabEnigme=array(); $tabEnigme=EnigmeFactory::create($results);
foreach ($results as $row) return $tabEnigme;
{ }
$tabEnigme[]= new Enigme(row['id'],row['admin'],row['enonce'],row['aide'],row['rappel'],row['solution'],row['test'],row['tempsDeResolution']);
} public function findByTempsDeResolution() : array
return $tabEnigme; {
$query = "SELECT * FROM Enigme ORDER BY tempsDeResolution";
$this->con->executequery($query);
$results = $this->con->getResults();
$tabEnigme=EnigmeFactory::create($results);
return $tabEnigme;
} }
public function showAll(): void public function showAll(): void
@ -72,6 +78,7 @@ class EnigmeGateway
echo $row['rappel'] . '</br>'; echo $row['rappel'] . '</br>';
echo $row['solution'] . '</br>'; echo $row['solution'] . '</br>';
echo $row['test'] . '</br>'; echo $row['test'] . '</br>';
echo $row['points'] . '</br>';
} }
} }
} }

@ -1,4 +1,6 @@
<?php <?php
include_once "EnigmeGateway";
class PartieGateway class PartieGateway
{ {
private Connection $con; private Connection $con;
@ -11,6 +13,7 @@ class PartieGateway
$this->con = $con; $this->con = $con;
} }
public function insert(Partie $partie){ public function insert(Partie $partie){
$query= "INSERT INTO Game VALUES (:idPartie)"; $query= "INSERT INTO Game VALUES (:idPartie)";
$this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), PDO::PARAM_STR))); $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), PDO::PARAM_STR)));
} }

@ -0,0 +1,12 @@
<?php
class EnigmeFactory{
public static function create($results)
{
$tabEnigme=array();
foreach($results as $row)
{
$tabEnigme[]= new Enigme($row['id'],$row['admin'],$row['enonce'],$row['aide'],$row['rappel'],$row['solution'],$row['test'],$row['tempsDeResolution'],$row['points']);
}
return $tabEnigme;
}
}

@ -0,0 +1,12 @@
<?php
class PartieFactory{
public static function create($results)
{
$tabPartie=array();
foreach($results as $row)
{
$tabPartie= new Partie($row['id']);
}
return $tabPartie;
}
}

@ -10,6 +10,7 @@ class Enigme
private string $solution; private string $solution;
private string $test; private string $test;
private int $tempsDeResolution; private int $tempsDeResolution;
private int $points;
/** /**
* @param string $idEnigme * @param string $idEnigme
@ -28,7 +29,7 @@ class Enigme
call_user_func(array(array($this,$function),$arguments)); call_user_func(array(array($this,$function),$arguments));
} }
public function __constructMulti(string $idEnigme, string $enonce, string $solution, string $test, int $tempsDeResolution,string $admin){ public function __constructMulti(string $idEnigme, string $enonce, string $solution, string $test, int $tempsDeResolution,string $admin,int $points){
$this->idEnigme=$idEnigme; $this->idEnigme=$idEnigme;
$this->enonce=$enonce; $this->enonce=$enonce;
$this->solution=$solution; $this->solution=$solution;
@ -37,6 +38,7 @@ class Enigme
$this->aide=NULL; $this->aide=NULL;
$this->rappel=NULL; $this->rappel=NULL;
$this->admin=$admin; $this->admin=$admin;
$this->points=$points;
} }
public function __constructSolo(string $idEnigme, string $enonce, string $aide, string $rappel, string $solution, string $test,string $admin){ public function __constructSolo(string $idEnigme, string $enonce, string $aide, string $rappel, string $solution, string $test,string $admin){
@ -177,4 +179,12 @@ class Enigme
{ {
$this->tempsDeResolution = $tempsDeResolution; $this->tempsDeResolution = $tempsDeResolution;
} }
public function getPoints(): int
{
return $this->points;
}
public function setPoints(int $points): void
{
$this->points = $points;
}
} }

@ -1,11 +1,12 @@
<?php <?php
include_once "Enigme.php";
class Partie class Partie
{ {
private string $idPartie; private string $idPartie;
private $datePartie; private $datePartie;
private array $listeEnigme;
/** /**
* @param string $idPartie * @param string $idPartie
@ -15,6 +16,7 @@ class Partie
{ {
$this->idPartie = $idPartie; $this->idPartie = $idPartie;
$this->datePartie = getdate(); $this->datePartie = getdate();
$listeEnigme = [];
} }
/** /**

Loading…
Cancel
Save