Ajout de la méthode ResoudreEnigmeMulti

ServeurDeTest
Johan LACHENAL 2 years ago
parent bcded9a6ae
commit c898502d06

@ -25,15 +25,15 @@ class EnigmeGateway
{
$query = "INSERT INTO Enigme VALUES (:id,:admin,:enonce,:aide,:rappel,:solution,:test,:tempsDeResolution,:points)";
$this->con->executeQuery($query, array(
':id' => array($enigme->getIdEnigme(), PDO::PARAM_STR),
':admin' => array($enigme->getAdmin(), PDO::PARAM_STR),
':enonce' => array($enigme->getEnonce(), PDO::PARAM_STR),
':aide' => array($enigme->getAide(), PDO::PARAM_STR),
':rappel' => array($enigme->getRappel(), PDO::PARAM_STR),
':solution' => array($enigme->getSolution(), PDO::PARAM_STR),
':test' => array($enigme->getTest(), PDO::PARAM_STR),
':tempsDeResolution' => array($enigme->getTempsDeResolution(), PDO::PARAM_INT),
':points' => array($enigme->getPoints(), PDO::PARAM_INT)
':id' => array($enigme->getIdEnigme(),SQLITE3_INTEGER),
':admin' => array($enigme->getAdmin(), SQLITE3_TEXT),
':enonce' => array($enigme->getEnonce(), SQLITE3_TEXT),
':aide' => array($enigme->getAide(), SQLITE3_TEXT),
':rappel' => array($enigme->getRappel(), SQLITE3_TEXT),
':solution' => array($enigme->getSolution(), SQLITE3_TEXT),
':test' => array($enigme->getTest(), SQLITE3_TEXT),
':tempsDeResolution' => array($enigme->getTempsDeResolution(), SQLITE3_INTEGER),
':points' => array($enigme->getPoints(), SQLITE3_INTEGER)
));
}
@ -41,7 +41,7 @@ class EnigmeGateway
{
$query= "DELETE FROM Enigme WHERE idEnigme=:idEnigme";
$this->con->executequery($query, array(
':idEnigme' => array($idEnigme,PDO::PARAM_STR)
':idEnigme' => array($idEnigme,SQLITE3_INTEGER)
));
}
@ -49,7 +49,7 @@ class EnigmeGateway
{
$query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme";
$this->con->executequery($query,array(
':idEnigme' => array($idEnigme,PDO::PARAM_STR)
':idEnigme' => array($idEnigme,SQLITE3_INTEGER)
));
$results=$this->con->getResults();
$tabEnigme=EnigmeFactory::create($results);

@ -12,7 +12,12 @@ class PartieGateway
{
$this->con = $con;
}
public function creerPartie(){
/**
* @param array $listeJoueur
*/
public function creerPartie(array $listeJoueur){
$query = "SELECT * FROM Enigme";
$this->con->executeQuery($query);
$results = $this->con->getResults();
@ -22,20 +27,27 @@ class PartieGateway
$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(), SQLITE3_INTEGER)));
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)));
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)));
}
foreach($listeJoueur as $Joueur){
$query= "INSERT INTO Participer VALUES (:idPartie, :idJoueur, TRUE)";
$this->con->executeQuery($query, array(
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)));
}
}
public function delete(string $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, SQLITE3_INTEGER)));
}
public function findOldListePartie() : array{
public function findPartieHistory() : array{
$query="SELECT * FROM Partie";
$this->con->executeQuery($query);
$results = $this->con->getResults();
@ -43,52 +55,23 @@ class PartieGateway
FROM PARTIE p;";
$this->con->executeQuery($query);
$max=$this->con->getResults()[0];
$listePartie=array();
$listePartieHistory=array();
foreach($results as $row)
{
$query = "SELECT e.* FROM Enigme e,Contenir c,Partie p
WHERE p.id = c.partie
AND c.enigme = e.id";
$this->con->executeQuery($query);
$listeEnigme=$this->con->getResults();
$listePartie[]=PartieFactory::createPartie($max,$listeEnigme);
AND c.enigme = e.id
AND c.enCours = false;
AND p.partie = :idPartie";
$this->con->executeQuery($query,array(
"idPartie" => array($row["idPartie"],SQLITE3_INTEGER)
));
$historiquePartie=$this->con->getResults();
$listePartieHistory[]=PartieFactory::createPartieHistory($row["idPartie"],$historiquePartie);
}
return $listePartie;
return $listePartieHistory;
}
public function getDashBoardData(Partie $partie) : array{
$query="SELECT joueur
FROM Participer p
WHERE p.partie=:idPartie";
$this->con->executeQuery($query,array(
'idPartie' => array($partie->getIdPartie(),PDO::PARAM_INT)));
$listeIdJoueur=$this->con->getResults();
$DashboardData=array();
foreach($listeIdJoueur as $joueur){
$points=0;
$query="SELECT pe.utilisateur,pe.points,pe.temps,u.pseudo
FROM Utilisateur u,PasserEnigme pe,Partie p
WHERE points IS NOT NULL
AND u.email=pe.utilisateur
AND pe.partie=:idPartie
AND pe.utilisateur=:joueur
GROUP BY pe.utilisateur,pe.points,pe.temps,u.pseudo
ORDER BY u.pseudo,pe.temps ASC";
$this->con->executequery($query,array(
'idPartie' => array($partie->getIdPartie(),PDO::PARAM_INT),
'joueur' => array($joueur,PDO::PARAM_STR)));
$results=$this->con->getResults();
$joueurDashboardData=array();
foreach($results as $row)
{
$points+=$row['pe.points'];
$joueurDashboardData[]=array($points,$row['pe.temps']);
}
$DashboardData[]=array($results[0]['u.pseudo'] => $joueurDashboardData);
}
return $DashboardData;
}
public function showAll() : void{
$query= "SELECT * FROM Partie";
$this->con->executeQuery($query);

@ -71,7 +71,7 @@ class UserController
throw (new Exception("Email déjà utilisé"));
}
$password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT);
$Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password);
$Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, false);
$gateway->insert($Utilisateur);
$_SESSION['connected'] = 'true';
$_SESSION['role'] = 'utilisateur';

@ -51,7 +51,7 @@ class UtilisateurGateway
if ($results == null){
return new Utilisateur("null", "null", "null", false);
}
return new Utilisateur($email, $pseudo, $mdp, $estAdmin,false);
return new Utilisateur($email, $pseudo, $mdp,false);
}
public function getMdpByEmail(string $email) : string{
@ -84,6 +84,58 @@ class UtilisateurGateway
return $estAdmin;
}
public function resoudreEnigmeMulti(string $emailUtilisateur)
{
$query="SELECT c.partie FROM Contenir
WHERE c.joueur = :emailUtilisateur
and c.enCours = TRUE";
$this->con->executeQuery($query, array(
':emailUtilisateur' => array($emailUtilisateur,SQLITE3_TEXT)
));
$idPartie=$this->con->getResults()[0];
$query="SELECT e.id FROM Resoudre r, Contenir c1,Contenir c2, Enigme e WHERE
r.id = :idPartie
AND r.joueur=:idJoueur
AND r.partie=:idPartie
AND r.temps IS NOT NULL
AND c1.partie = r.partie
AND c2.index=c1.index + 1
AND e.id = c1.enigme
AND r.temps = (SELECT max(r.temps))";
$results=$this->con->getResults();
if(empty($results))
$query="SELECT enigme FROM Contenir WHERE
c.partie = :idPartie
AND c.indexEnigme = 0";
$results=$this->con->getResults();
$idEnigme=$results[0];
$query="SELECT max(classement) FROM Enigme e,Partie p, Resoudre r
WHERE p.id=r.partie;
AND e.id=r.enigme";
$this->con->executeQuery($query);
$results=$this->con->getResults();
if(empty($results))
$classement=1;
else
$classement=$results[0]+1;
$query="INSERT INTO Resoudre VALUES (:joueur, :enigme,:partie,:classement,:index,:temps,TRUE)";
$this->con->executeQuery($query, array(
"joueur" => array($emailUtilisateur, SQLITE3_TEXT),
"enigme" => array($idEnigme, SQLITE3_TEXT),
"partie" => array($idPartie, SQLITE3_TEXT),
"classement" => array($classement, SQLITE3_INTEGER),
"index" => array(, SQLITE3_INTEGER),
"temps" => array($emailUtilisateur, SQLITE3_FLOAT)));
}
public function resoudreEnigmeSolo(string $emailUtilisateur, int $idEnigme, int $idPartie)
{
$query="INSERT INTO Resoudre VALUES (:joueur, :enigme,:partie,NULL,:index,:temps,False)";
}
public function showAll() : void{
$query = "SELECT * FROM Utilisateur";
$this->con->executeQuery($query);

@ -18,4 +18,9 @@ class PartieFactory{
$partie=new Partie($idMax,$resultsEnigme);
return $partie;
}
public static function createPartieHistory($id,$resultsEnigme) : Partie
{
$partie=new Partie($id,$resultsEnigme);
return $partie;
}
}
Loading…
Cancel
Save