You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.0 KiB
57 lines
2.0 KiB
<?php
|
|
|
|
include_once "../Factory/PartieFactory.php";
|
|
class PartieGateway
|
|
{
|
|
private Connection $con;
|
|
|
|
/**
|
|
* @param Connection $con
|
|
*/
|
|
public function __construct(Connection $con)
|
|
{
|
|
$this->con = $con;
|
|
}
|
|
public function creerPartie(){
|
|
$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(), 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){
|
|
$query= "DELETE FROM Partie WHERE id = :idPartie";
|
|
$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 showAll() : void{
|
|
$query= "SELECT * FROM Partie";
|
|
$this->con->executeQuery($query);
|
|
$results=$this->con->getResults();
|
|
foreach ($results as $row) {
|
|
echo $row['idPartie'] . '</br>';
|
|
}
|
|
}
|
|
} |