|
|
@ -21,7 +21,8 @@ class PartieGateway
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param array $listeUtilisateur
|
|
|
|
* @param array $listeUtilisateur
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function partieInQueueExists() : bool{
|
|
|
|
public function partieInQueueExists(): bool
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "SELECT count(*) FROM PARTICIPER WHERE etat = 0";
|
|
|
|
$query = "SELECT count(*) FROM PARTICIPER WHERE etat = 0";
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$results = $this->con->getResults();
|
|
|
@ -31,7 +32,8 @@ class PartieGateway
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function findPartieMaxId() : int{
|
|
|
|
public function findPartieMaxId(): int
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "SELECT max(id) FROM Partie";
|
|
|
|
$query = "SELECT max(id) FROM Partie";
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$results = $this->con->getResults();
|
|
|
@ -40,40 +42,45 @@ class PartieGateway
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return $results[0]['max(id)'];
|
|
|
|
return $results[0]['max(id)'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function creerPartieMulti(int $max, array $tabEnigme) : Partie{
|
|
|
|
// public function creerPartieMulti(int $max, array $tabEnigme) : Partie{
|
|
|
|
$partie=PartieFactory::createPartieMulti($max+1,$tabEnigme);
|
|
|
|
// $partie=PartieFactory::createPartieMulti($max+1,$tabEnigme);
|
|
|
|
$query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)";
|
|
|
|
// $query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)";
|
|
|
|
$this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER)));
|
|
|
|
// $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER)));
|
|
|
|
if (count($partie->getListeEnigme()) != 0) {
|
|
|
|
// if (count($partie->getListeEnigme()) != 0) {
|
|
|
|
foreach ($partie->getListeEnigme() as $Enigme) {
|
|
|
|
// foreach ($partie->getListeEnigme() as $Enigme) {
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
|
|
|
|
// $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
// $this->con->executeQuery($query, array(
|
|
|
|
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
// ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)
|
|
|
|
// ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)
|
|
|
|
)
|
|
|
|
// )
|
|
|
|
);
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
return $partie;
|
|
|
|
// return $partie;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public function rejoindrePartieMulti(int $idPartieInQueue,array $tabEnigme) : Partie{
|
|
|
|
public function rejoindrePartieMulti(int $idPartieInQueue, array $tabEnigme): Partie
|
|
|
|
|
|
|
|
{
|
|
|
|
$partie = PartieFactory::createPartieMulti($idPartieInQueue, $tabEnigme);
|
|
|
|
$partie = PartieFactory::createPartieMulti($idPartieInQueue, $tabEnigme);
|
|
|
|
return $partie;
|
|
|
|
return $partie;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function findPartieInQueue(){
|
|
|
|
public function findPartieInQueue()
|
|
|
|
$query = "SELECT p.id
|
|
|
|
{
|
|
|
|
FROM Partie p, Participer pa
|
|
|
|
$query = "SELECT partie
|
|
|
|
WHERE pa.etat=0
|
|
|
|
FROM Participer
|
|
|
|
AND pa.partie=p.id
|
|
|
|
WHERE etat=0
|
|
|
|
LIMIT 1";
|
|
|
|
LIMIT 1";
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
return $results[0]['id'];
|
|
|
|
if (empty($results)) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results[0]['partie'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function creerPartieSolo(Utilisateur $utilisateur){
|
|
|
|
public function creerPartieSolo(Utilisateur $utilisateur)
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "SELECT * FROM Enigme
|
|
|
|
$query = "SELECT * FROM Enigme
|
|
|
|
WHERE points IS NULL OR points = 0";
|
|
|
|
WHERE points IS NULL OR points = 0";
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
@ -89,18 +96,24 @@ class PartieGateway
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)));
|
|
|
|
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($partie->getListeEnigme() as $Enigme) {
|
|
|
|
foreach ($partie->getListeEnigme() as $Enigme) {
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)));
|
|
|
|
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$query = "INSERT INTO Participer VALUES (:idPartie, :idUtilisateur, TRUE)";
|
|
|
|
$query = "INSERT INTO Participer VALUES (:idPartie, :idUtilisateur, TRUE)";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
'idUtilisateur' => array($utilisateur->getEmail(), SQLITE3_INTEGER)));
|
|
|
|
'idUtilisateur' => array($utilisateur->getEmail(), SQLITE3_INTEGER)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function findLastPartie(): Partie
|
|
|
|
public function findLastPartie(): Partie
|
|
|
@ -115,23 +128,54 @@ class PartieGateway
|
|
|
|
return $partie;
|
|
|
|
return $partie;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function createPartie(Enigme $enigme, Utilisateur $utilisateur){
|
|
|
|
public function createPartie(Enigme $enigme, Utilisateur $utilisateur)
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "INSERT INTO Partie VALUES (NULL,:date)";
|
|
|
|
$query = "INSERT INTO Partie VALUES (NULL,:date)";
|
|
|
|
$currentDate = date('Y-m-d H:i:s');
|
|
|
|
$currentDate = date('Y-m-d H:i:s');
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
"date" => array($currentDate, SQLITE3_TEXT)));
|
|
|
|
"date" => array($currentDate, SQLITE3_TEXT)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
$partie = $this->findLastPartie();
|
|
|
|
$partie = $this->findLastPartie();
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,NULL)";
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,NULL)";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
"idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER)));
|
|
|
|
"idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
$query = "INSERT INTO Participer VALUES (:partie,:utilisateur,NULL)";
|
|
|
|
$query = "INSERT INTO Participer VALUES (:partie,:utilisateur,NULL)";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
"utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT)));
|
|
|
|
"utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function createPartieMulti(Enigme $enigme, string $mailUtilisateur)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$query = "INSERT INTO Partie VALUES (NULL,:date)";
|
|
|
|
|
|
|
|
$currentDate = date('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
"date" => array($currentDate, SQLITE3_TEXT)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$partie = $this->findLastPartie();
|
|
|
|
|
|
|
|
$query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)";
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
|
|
|
|
"idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)";
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
|
|
|
|
|
|
|
|
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function delete(int $idPartie){
|
|
|
|
public function delete(int $idPartie)
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "DELETE FROM Contenir WHERE partie = :enigmeId";
|
|
|
|
$query = "DELETE FROM Contenir WHERE partie = :enigmeId";
|
|
|
|
$this->con->executeQuery($query, array(':enigmeId' => array($idPartie, SQLITE3_INTEGER)));
|
|
|
|
$this->con->executeQuery($query, array(':enigmeId' => array($idPartie, SQLITE3_INTEGER)));
|
|
|
|
$query = "DELETE FROM Participer WHERE partie = :enigmeId";
|
|
|
|
$query = "DELETE FROM Participer WHERE partie = :enigmeId";
|
|
|
@ -140,7 +184,8 @@ class PartieGateway
|
|
|
|
$this->con->executeQuery($query, array(':idPartie' => array($idPartie, SQLITE3_INTEGER)));
|
|
|
|
$this->con->executeQuery($query, array(':idPartie' => array($idPartie, SQLITE3_INTEGER)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function deleteByEnigme(int $enigmeId){
|
|
|
|
public function deleteByEnigme(int $enigmeId)
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "SELECT partie FROM Contenir WHERE enigme = :enigmeId";
|
|
|
|
$query = "SELECT partie FROM Contenir WHERE enigme = :enigmeId";
|
|
|
|
$this->con->executeQuery($query, array(':enigmeId' => array($enigmeId, SQLITE3_INTEGER)));
|
|
|
|
$this->con->executeQuery($query, array(':enigmeId' => array($enigmeId, SQLITE3_INTEGER)));
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$results = $this->con->getResults();
|
|
|
@ -156,7 +201,8 @@ class PartieGateway
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function findPartieHistory() : array{
|
|
|
|
public function findPartieHistory(): array
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "SELECT * FROM Partie";
|
|
|
|
$query = "SELECT * FROM Partie";
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$results = $this->con->getResults();
|
|
|
@ -165,8 +211,7 @@ class PartieGateway
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$max = $this->con->getResults()[0]["max"];
|
|
|
|
$max = $this->con->getResults()[0]["max"];
|
|
|
|
$listePartieHistory = array();
|
|
|
|
$listePartieHistory = array();
|
|
|
|
foreach($results as $row)
|
|
|
|
foreach ($results as $row) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$query = "SELECT e.* FROM Enigme e,Contenir c,Partie p
|
|
|
|
$query = "SELECT e.* FROM Enigme e,Contenir c,Partie p
|
|
|
|
WHERE p.id = c.partie
|
|
|
|
WHERE p.id = c.partie
|
|
|
|
AND c.enigme = e.id
|
|
|
|
AND c.enigme = e.id
|
|
|
@ -174,19 +219,22 @@ class PartieGateway
|
|
|
|
AND p.partie = :idPartie";
|
|
|
|
AND p.partie = :idPartie";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
"idPartie" => array($row["idPartie"], SQLITE3_INTEGER)
|
|
|
|
"idPartie" => array($row["idPartie"], SQLITE3_INTEGER)
|
|
|
|
));
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
$historiquePartie = $this->con->getResults();
|
|
|
|
$historiquePartie = $this->con->getResults();
|
|
|
|
$listePartieHistory[] = PartieFactory::createPartieHistory($row["idPartie"], $historiquePartie);
|
|
|
|
$listePartieHistory[] = PartieFactory::createPartieHistory($row["idPartie"], $historiquePartie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $listePartieHistory;
|
|
|
|
return $listePartieHistory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function findPartieByEnigmeId(int $enigmeId) : Partie{
|
|
|
|
public function findPartieByEnigmeId(int $enigmeId): Partie
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "SELECT * FROM Partie p, Resoudre r
|
|
|
|
$query = "SELECT * FROM Partie p, Resoudre r
|
|
|
|
WHERE r.enigme = :enigmeId
|
|
|
|
WHERE r.enigme = :enigmeId
|
|
|
|
AND r.partie = p.id";
|
|
|
|
AND r.partie = p.id";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
':enigmeId' => array($enigmeId, SQLITE3_INTEGER)
|
|
|
|
':enigmeId' => array($enigmeId, SQLITE3_INTEGER)
|
|
|
|
));
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$row = $results[0];
|
|
|
|
$row = $results[0];
|
|
|
|
$partie = new Partie($row['id'], array());
|
|
|
|
$partie = new Partie($row['id'], array());
|
|
|
@ -195,7 +243,49 @@ class PartieGateway
|
|
|
|
return $partie;
|
|
|
|
return $partie;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function showAll() : void{
|
|
|
|
public function addToPartie(string $mailUtilisateur, int $idPartie)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
global $playerNumberPerGame;
|
|
|
|
|
|
|
|
$player = $this->getPlayerNumber($idPartie);
|
|
|
|
|
|
|
|
if ($player == $playerNumberPerGame) {
|
|
|
|
|
|
|
|
throw new Exception("La partie est pleine");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($player + 1 == $playerNumberPerGame) {
|
|
|
|
|
|
|
|
$query = "INSERT INTO Participer VALUES (:partie,:utilisateur,1)";
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
"partie" => array($idPartie, SQLITE3_INTEGER),
|
|
|
|
|
|
|
|
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
$query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)";
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
"partie" => array($idPartie, SQLITE3_INTEGER),
|
|
|
|
|
|
|
|
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPlayerNumber(int $idPartie): int
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$query = "SELECT count(*) FROM Participer WHERE partie = :idPartie";
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
"idPartie" => array($idPartie, SQLITE3_INTEGER)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
|
|
|
|
$row = $results[0];
|
|
|
|
|
|
|
|
return $row['count(*)'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEtat($idPartie){
|
|
|
|
|
|
|
|
$query = "SELECT etat FROM Participer WHERE partie = :idPartie";
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
"idPartie" => array($idPartie, SQLITE3_INTEGER)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
|
|
|
|
$row = $results[0];
|
|
|
|
|
|
|
|
return $row['etat'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showAll(): void
|
|
|
|
|
|
|
|
{
|
|
|
|
$query = "SELECT * FROM Partie";
|
|
|
|
$query = "SELECT * FROM Partie";
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$results = $this->con->getResults();
|
|
|
|
$results = $this->con->getResults();
|
|
|
|