parent
297046972c
commit
927da5e15b
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
require_once("Gateway.php");
|
||||
class CompteGateway implements Gateway
|
||||
{
|
||||
private $conn;
|
||||
public function __construct($conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
public function inserer($itemAInserer)
|
||||
{
|
||||
if(get_class($itemAInserer) != "Compte")
|
||||
{
|
||||
throw new TypeError("L'élement à inserer doit être de type compte");
|
||||
}
|
||||
|
||||
$requette = "INSERT INTO _Compte(pseudonyme, dateCreation, motDePasse)
|
||||
VALUSES(:pseudo, :date, :mdp)";
|
||||
return $this->conn->executeQuerry($requette, [
|
||||
":pseudo" => [$itemAInserer->getPseudonyme(), PDO::PARAM_STR],
|
||||
":date" => ["STR_TO_DATE(".$itemAInserer->getDateCreation().")", PDO::PARAM_STR],
|
||||
":mdp" => [$itemAInserer->getMotDePasse(), PDO::PARAM_STR]
|
||||
]);
|
||||
}
|
||||
|
||||
public function modifier($itemAModifier)
|
||||
{
|
||||
if(get_class($itemAInserer) != "Compte")
|
||||
{
|
||||
throw new TypeError("L'élement à modifier doit être de type compte");
|
||||
}
|
||||
$requette = "UPDATE _Compte SET pseudonyme=:pseudo, dateCreation=:date, motDePasse=:mdp";
|
||||
return $this->conn->executeQuerry($requette, [
|
||||
":pseudo" => [$itemAModifier->getPseudonyme(), PDO::PARAM_STR],
|
||||
":date" => [$itemAModifier->getDateCreation(), PDO::PARAM_STR],
|
||||
":mdp" => [$itemAModifier->getMotDePasse(), PDO::PARAM_STR]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function supprimer($itemASupprimer)
|
||||
{
|
||||
if(get_class($itemAInserer) != "Compte")
|
||||
{
|
||||
throw new TypeError("L'élement à supprimer doit être de type compte");
|
||||
}
|
||||
$requette = "DELETE FROM _Compte WHERE compteID=:id";
|
||||
return $this->conn->executeQuerry($requette, [
|
||||
":id" => [$itemAModifier->getID(), PDO::PARAM_INT]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function getCompteParPseudo(string $pseudo) : iterable
|
||||
{
|
||||
$requete = "SELECT * FROM _Compte WHERE pseudonyme=:pseudo";
|
||||
|
||||
if(!$this->conn->executeQuerry($requete, [":pseudo" => [$pseudo, PDO::PARAM_STR]]))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
$comptesSQL = $this->conn->getResults();
|
||||
$comptes = array();
|
||||
$listes = array();
|
||||
$requete = "SELECT * FROM _TodoList WHERE Createur=:id";
|
||||
|
||||
foreach($comptesSQL as $compte)
|
||||
{
|
||||
if(!$this->conn->executeQuerry($requete, [":id" => [$compte["compteID", PDO::PARAM_STR]]))
|
||||
{
|
||||
$listes = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$listesSQL = $this->conn->getResults();
|
||||
foreach($listesSQL as $liste)
|
||||
{
|
||||
$listes[] = new TodoList(
|
||||
$liste["listeID"],
|
||||
$liste["nom"],
|
||||
$liste["Createur"],
|
||||
$liste["dateCreation"],
|
||||
$liste["public"]
|
||||
);
|
||||
}
|
||||
}
|
||||
$comptes[] = new Compte(
|
||||
$compte["pseudonyme"],
|
||||
$compte["dateCreation"],
|
||||
$listes,
|
||||
$compte["motDePasse"],
|
||||
$compte["compteID"]
|
||||
);
|
||||
return $comptes;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
interface Gateway
|
||||
{
|
||||
public function inserer($itemAInserer);
|
||||
public function modifier($itemAModifier);
|
||||
public function supprimer($itemASupprimer);
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
class ListeGateway
|
||||
{
|
||||
|
||||
private $conn;
|
||||
|
||||
public function __construct($conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
public function inserer($l) : bool
|
||||
{
|
||||
$requete = "INSERT INTO _TodoList(nom, dateCreation, public, createur)
|
||||
VALUES(:nom, :date, :pub, :createur)";
|
||||
return $this->conn->executeQuery($requete,
|
||||
":nom" => [$l->getNom(), PDO::PARAM_STR],
|
||||
":date" => ["STR_TO_DATE(".$l->getDateCreation().")", PDO::PARAM_STR],
|
||||
":pub" => [$l->estPublic(), PDO::PARAM_BOOL],
|
||||
":createur" => [$l->getCreateur(), PDO::PARAM_INT]
|
||||
]);
|
||||
}
|
||||
|
||||
public function supprimer($l) : bool
|
||||
{
|
||||
$requete = "DELETE FROM _TodoList WHERE listeID=:id";
|
||||
return $this->conn->executeQuery($requete,[
|
||||
":id"=>[$l->getID(), PDO::PARAM_INT]
|
||||
]);
|
||||
}
|
||||
|
||||
public function modifier($l) : bool
|
||||
{
|
||||
$requete="UPDATE _TodoList SET
|
||||
nom=:n, public=:p";
|
||||
return $this->conn->executeQuery($requete, [
|
||||
":n" => [$l->getNom(), PDO::PARAM_STR],
|
||||
":p" => [$l->estPublic(), PDO::PARAM_BOOL]
|
||||
]);
|
||||
}
|
||||
public function listeParDate(int $page, int $nbTache) : iterable
|
||||
{
|
||||
$lites = array();
|
||||
$requete = "SELECT * FROM _TodoList ORDER BY dateCreation LIMIT (:p -1)+:n, :n";
|
||||
$isOK=$this->conn->executeQuery($requete, [
|
||||
":p" => [$page, PDO::PARAM_INT],
|
||||
":n" => [$nbTache, PDO::PARAM_INT]
|
||||
]);
|
||||
if(!$isOK)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$res = $this->conn->getResults();
|
||||
|
||||
foreach($res as $liste)
|
||||
{
|
||||
$listes[] = new TodoList(
|
||||
$liste["listeID"],
|
||||
$liste["nom"],
|
||||
$liste["Createur"],
|
||||
$liste["dateCreation"],
|
||||
$liste["public"]
|
||||
);
|
||||
}
|
||||
return $listes;
|
||||
}
|
||||
public function listeParNom() : iterable
|
||||
{
|
||||
$lites = array();
|
||||
$requete = "SELECT * FROM _TodoList ORDER BY nom LIMIT (:p -1)+:n, :n";
|
||||
$isOK=$this->conn->executeQuery($requete, [
|
||||
":p" => [$page, PDO::PARAM_INT],
|
||||
":n" => [$nbTache, PDO::PARAM_INT]
|
||||
]);
|
||||
if(!$isOK)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$res = $this->conn->getResults();
|
||||
|
||||
foreach($res as $liste)
|
||||
{
|
||||
$listes[] = new TodoList(
|
||||
$liste["listeID"],
|
||||
$liste["nom"],
|
||||
$liste["Createur"],
|
||||
$liste["dateCreation"],
|
||||
$liste["public"]
|
||||
);
|
||||
}
|
||||
return $listes;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
require_once('modèle/Tache.php');
|
||||
require_once('modèle/Validation.php');
|
||||
require_once('modèle/Connection.php');
|
||||
require_once('Gateway.php');
|
||||
|
||||
|
||||
class TacheGateway implements Gateway
|
||||
{
|
||||
// Attributs
|
||||
private $conn;
|
||||
//------------------------------
|
||||
// Méthodes magiques
|
||||
public function __construct(Connection $conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
}
|
||||
//------------------------------
|
||||
// Méthodes pérsonalisées
|
||||
|
||||
public function inserer($itemAInserer)
|
||||
{
|
||||
if(get_class($itemAInserer) != "Tache")
|
||||
{
|
||||
throw new TypeError("L'item à inserer doit être une Tache");
|
||||
}
|
||||
$requette = "INSERT INTO _Tache(NomTache, TacheFaite, Commentaire, Couleur) VALUES(
|
||||
:nom, :fait, :commentaire, :couleur
|
||||
)";
|
||||
|
||||
return $this->conn->executeQuery($requette, [
|
||||
':nom' => [$itemAInserer->nom, PDO::PARAM_STR],
|
||||
':fait'=> [$itemAInserer->estFait, PDO::PARAM_BOOL],
|
||||
':commentaire' => [$itemAInserer->commentaire, PDO::PARAM_STR],
|
||||
':couleur' => [$itemAInserer->couleur, PDO::PARAM_STR]
|
||||
]);
|
||||
}
|
||||
|
||||
public function modifier($itemAModifier)
|
||||
{
|
||||
if(get_class($itemAInserer) != "Tache")
|
||||
{
|
||||
throw new TypeError("L'item à modifier doit être une Tache");
|
||||
}
|
||||
$requette = "UPDATE _Tache SET
|
||||
NomTache = :nom,
|
||||
Commentaire = :commentaire,
|
||||
Couleur = :couleur,
|
||||
TacheFaite = :fait
|
||||
WHERE
|
||||
tacheID = :id";
|
||||
return $this->conn->executeQuery($requette,[
|
||||
':nom' => [$itemAModifier->nom, PDO::PRAM_STR],
|
||||
':commentaire' => [$itemAModifier->commentaire, PDO::PARAM_STR],
|
||||
':couleur' => [$itemAModifier->couleur, PDO::PARAM_STR],
|
||||
':fait' => [$itemAModifier->estFait, PDO::PARAM_BOOL]
|
||||
]);
|
||||
}
|
||||
|
||||
public function supprimer($itemASupprimer)
|
||||
{
|
||||
if(get_class($itemAInserer) != "Tache")
|
||||
{
|
||||
throw new TypeError("L'item à supprimer doit être une Tache");
|
||||
}
|
||||
$requette = "DELETE FROM _Tache WHERE tacheID=:id";
|
||||
return $this->conn->executeQuery($requette,
|
||||
[':id', [$itemASupprimer->tacheID]]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function getTacheParListe(TodoList $l) : iterable
|
||||
{
|
||||
$requete = "SELECT * FROM _Tache WHERE listID=:id";
|
||||
if(!$this->conn->executeQuery($requete,
|
||||
[":id" => [$l->getID()]]))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$res = $this->conn->getResults();
|
||||
$taches = array();
|
||||
foreach($res as $tache)
|
||||
{
|
||||
$taches[] = new Tache(
|
||||
$tache["NomTache"],
|
||||
$tache["TacheFaite"],
|
||||
$tache["Commentaire"],
|
||||
$tache["Couleur"],
|
||||
$tache["tacheID"]
|
||||
);
|
||||
}
|
||||
return $taches;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue