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.
78 lines
2.4 KiB
78 lines
2.4 KiB
<?php
|
|
|
|
class EnigmeGateway
|
|
{
|
|
private Connection $con;
|
|
|
|
/**
|
|
* @param Connection $con
|
|
*/
|
|
|
|
public function __construct(Connection $con)
|
|
{
|
|
$this->con = $con;
|
|
}
|
|
|
|
/**
|
|
* @param Connection $con
|
|
*/
|
|
public function setCon(Connection $con): void
|
|
{
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function insert(Enigme $enigme)
|
|
{
|
|
$query = "INSERT INTO Enigme VALUES (:id,:admin,:enonce,:aide,:rappel,:solution,:test,:tempsDeResolution)";
|
|
$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)
|
|
));
|
|
}
|
|
|
|
public function delete(string $idEnigme)
|
|
{
|
|
$query= "DELETE FROM Enigme WHERE idEnigme=:idEnigme";
|
|
$this->con->executequery($query, array(
|
|
':idEnigme' => array($idEnigme,PDO::PARAM_STR)
|
|
));
|
|
}
|
|
|
|
public function findById(string $idEnigme)
|
|
{
|
|
$query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme";
|
|
$this->con->executequery($query,array(
|
|
':idEnigme' => array($idEnigme,PDO::PARAM_STR)
|
|
));
|
|
$results=$this->con->getResults();
|
|
$tabEnigme=array();
|
|
foreach ($results as $row)
|
|
{
|
|
$tabEnigme[]= new Enigme(row['id'],row['admin'],row['enonce'],row['aide'],row['rappel'],row['solution'],row['test'],row['tempsDeResolution']);
|
|
}
|
|
return $tabEnigme;
|
|
}
|
|
|
|
public function showAll(): void
|
|
{
|
|
$query = "SELECT * FROM Enigme";
|
|
$this->con->executeQuery($query);
|
|
$results = $this->con->getResults();
|
|
foreach ($results as $row) {
|
|
echo $row['idEnigme'] . '</br>';
|
|
echo $row['admin'] . '</br>';
|
|
echo $row['enonce'] . '</br>';
|
|
echo $row['aide'] . '</br>';
|
|
echo $row['rappel'] . '</br>';
|
|
echo $row['solution'] . '</br>';
|
|
echo $row['test'] . '</br>';
|
|
}
|
|
}
|
|
}
|
|
?>
|