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.
Scripted/WEB/Controller/EnigmeGateway.php

108 lines
3.4 KiB

<?php
class EnigmeGateway
{
private Connection $con;
/**
* @param Connection $con
*/
public function __construct()
{
global $dsn, $rep, $vues, $error;
try{
$con = new Connection($dsn);
$this->con = $con;
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
/**
* @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,:points)";
$this->con->executeQuery($query, array(
':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)
));
}
public function delete(string $idEnigme)
{
$query= "DELETE FROM Enigme WHERE idEnigme=:idEnigme";
$this->con->executequery($query, array(
':idEnigme' => array($idEnigme,SQLITE3_INTEGER)
));
}
public function findMultiEnigma() : array
{
$query = "SELECT * FROM Enigme
WHERE points IS NOT NULL OR points != 0";
$this->con->executeQuery($query);
$tabEnigme=EnigmeFactory::create($this->con->getResults());
return $tabEnigme;
}
public function findSoloEnigma(){
$query = "SELECT * FROM Enigme
WHERE points IS NULL OR points = 0";
$this->con->executeQuery($query);
$tabEnigme=EnigmeFactory::create($this->con->getResults());
return $tabEnigme;
}
public function findById(string $idEnigme) : array
{
$query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme";
$this->con->executequery($query,array(
':idEnigme' => array($idEnigme,SQLITE3_INTEGER)
));
$results=$this->con->getResults();
$tabEnigme=EnigmeFactory::create($results);
return $tabEnigme;
}
public function findByTempsDeResolution() : array
{
$query = "SELECT * FROM Enigme ORDER BY tempsDeResolution";
$this->con->executequery($query);
$results = $this->con->getResults();
$tabEnigme=EnigmeFactory::create($results);
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>';
echo $row['points'] . '</br>';
}
}
}
?>