Partie gw + partie

factory
ServeurDeTest
Johan LACHENAL 2 years ago
parent a7e6a152f7
commit c06c60efa7

@ -1,6 +1,6 @@
<?php <?php
include_once "EnigmeGateway"; include_once "../Factory/PartieFactory.php";
class PartieGateway class PartieGateway
{ {
private Connection $con; private Connection $con;
@ -12,15 +12,47 @@ class PartieGateway
{ {
$this->con = $con; $this->con = $con;
} }
public function insert(Partie $partie){ public function creerPartie(){
$query = "SELECT * FROM Enigme";
$query= "INSERT INTO Game VALUES (:idPartie)"; $this->con->executeQuery($query);
$results = $this->con->getResults();
$query= "SELECT max(p.id)
FROM PARTIE p;";
$this->con->executeQuery($query);
$max=$this->con->getResults()[0];
$partie=PartieFactory::createPartie($max,$results);
$query= "INSERT INTO Partie VALUES (:idPartie,:idEnigme)";
$this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), PDO::PARAM_STR))); $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), PDO::PARAM_STR)));
foreach($partie->getListeEnigme() as $Enigme){
$query= "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
$this->con->executeQuery($query, array(
':idPartie' => array($partie->getIdPartie(), PDO::PARAM_STR),
':idEnigme' => array($Enigme->getIdEnigme(), PDO::PARAM_STR)));
}
} }
public function delete(string $idPartie){ public function delete(string $idPartie){
$query= "DELETE FROM Game WHERE idGame = :idPartie"; $query= "DELETE FROM Partie WHERE id = :idPartie";
$this->con->executeQuery($query, array(':idPartie' => array($idPartie, PDO::PARAM_STR))); $this->con->executeQuery($query, array(':idPartie' => array($idPartie, PDO::PARAM_STR)));
} }
public function findOldListeEnigme(string $partie) : array{
$query= "SELECT * FROM Enigme e,Contenir c
AND c.partie = :idPartie
AND c.enigme = e.id";
$this->con->executeQuery($query, array(':idPartie' => array(
':idPartie' => array($partie, PDO::PARAM_STR),
)));
$results=$this->con->getResults();
$tabEnigme=EnigmeFactory::create($results);
return $tabEnigme;
}
public function findIdMax(){
$query= "SELECT max(p.id)
FROM PARTIE p;";
$this->con->executeQuery($query);
$results=$this->con->getResults();
return $results[0]->max;
}
public function showAll() : void{ public function showAll() : void{
$query= "SELECT * FROM Partie"; $query= "SELECT * FROM Partie";
$this->con->executeQuery($query); $this->con->executeQuery($query);

@ -1,12 +1,22 @@
<?php <?php
include_once "EnigmeFactory.php";
include_once "../Model/Partie.php";
class PartieFactory{ class PartieFactory{
public static function create($results) public static function createPartie($idMax,$resultsEnigme) : Partie
{ {
$tabPartie=array(); $tempsResolutionPartie=0;
foreach($results as $row) $tabEnigme=array();
$tabIndex=range(0,strlen($resultsEnigme)-1);
$randomNumber=0;
while($tempsResolutionPartie <= 30)
{ {
$tabPartie= new Partie($row['id']); $randomNumber=$tabIndex[array_rand($tabIndex)];
$tabEnigme=EnigmeFactory::create($resultsEnigme[$randomNumber]);
$TempsResolutionPartie+=$resultsEnigme[$randomNumber]['tempsDeResolution'];
unset($tabIndex[$randomNumber]);
} }
return $tabPartie; $partie=new Partie($idMax,$resultsEnigme);
return $partie;
} }
//public static function createListePartie()
} }

@ -12,11 +12,11 @@ class Partie
* @param string $idPartie * @param string $idPartie
* @param array $datePartie * @param array $datePartie
*/ */
public function __construct(string $idPartie) public function __construct(string $idPartie, array $listeEnigme)
{ {
$this->idPartie = $idPartie; $this->idPartie = $idPartie;
$this->datePartie = getdate(); $this->datePartie = getdate();
$listeEnigme = []; $this->$listeEnigme = $listeEnigme;
} }
/** /**
@ -50,4 +50,17 @@ class Partie
{ {
$this->datePartie = $datePartie; $this->datePartie = $datePartie;
} }
/**
* @param array $listeEnigme
*/
public function getListeEnigme(): array
{
return $this->listeEnigme;
}
public function setListeEnigme(array $listeEnigme): void
{
$this->listeEnigme = $listeEnigme;
}
} }

@ -26,18 +26,19 @@ mdp varchar(50)
); );
CREATE TABLE Enigme( CREATE TABLE Enigme(
id char(5) PRIMARY KEY, id int PRIMARY KEY AUTO_INCREMENT,
admin varchar(50) REFERENCES Admin(email), admin varchar(50) REFERENCES Admin(email),
enonce varchar(250) NOT NULL, enonce varchar(250) NOT NULL,
aide varchar(250), aide varchar(250),
rappel varchar(250), rappel varchar(250),
solution varchar(250) NOT NULL, solution varchar(250) NOT NULL,
test varchar(250) NOT NULL, test varchar(250) NOT NULL,
tempsDeResolution numeric CHECK (tempsDeResolution >0) tempsDeResolution numeric CHECK (tempsDeResolution >0),
points numeric
); );
CREATE TABLE Partie( CREATE TABLE Partie(
id char(5) PRIMARY KEY id int PRIMARY KEY AUTO_INCREMENT,
); );
CREATE TABLE ResoudreEnSolo( CREATE TABLE ResoudreEnSolo(
@ -52,6 +53,7 @@ joueur varchar(50) REFERENCES Joueur(email),
enigme char(5) REFERENCES Enigme(id), enigme char(5) REFERENCES Enigme(id),
partie char(5) REFERENCES Partie(id), partie char(5) REFERENCES Partie(id),
indexEnigme numeric UNIQUE, indexEnigme numeric UNIQUE,
temps time,
PRIMARY KEY(joueur, enigme, partie) PRIMARY KEY(joueur, enigme, partie)
); );

Loading…
Cancel
Save