con = $con; } /** * @param array $listeJoueur */ public function creerPartie(array $listeJoueur){ $query = "SELECT * FROM Enigme"; $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(), SQLITE3_INTEGER))); foreach($partie->getListeEnigme() as $Enigme){ $query= "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; $this->con->executeQuery($query, array( ':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, SQLITE3_INTEGER))); } public function findPartieHistory() : array{ $query="SELECT * FROM Partie"; $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]; $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 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 $listePartieHistory; } public function showAll() : void{ $query= "SELECT * FROM Partie"; $this->con->executeQuery($query); $results=$this->con->getResults(); foreach ($results as $row) { echo $row['idPartie'] . '
'; } } }