commit
087d45389f
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Connection extends PDO {
|
||||||
|
|
||||||
|
private $stmt;
|
||||||
|
|
||||||
|
public function __construct(string $dsn, string $username, string $password) {
|
||||||
|
|
||||||
|
parent::__construct($dsn,$username,$password);
|
||||||
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** * @param string $query
|
||||||
|
* @param array $parameters *
|
||||||
|
* @return bool Returns `true` on success, `false` otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function executeQuery(string $query, array $parameters = []) : bool{
|
||||||
|
$this->stmt = parent::prepare($query);
|
||||||
|
foreach ($parameters as $name => $value) {
|
||||||
|
$this->stmt->bindValue($name, $value[0], $value[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResults() : array {
|
||||||
|
return $this->stmt->fetchall();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Liste {
|
||||||
|
private int $id;
|
||||||
|
private string $nom;
|
||||||
|
private $taches;
|
||||||
|
|
||||||
|
function __construct(int $i, string $n, $t){
|
||||||
|
$this->id=$i;
|
||||||
|
$this->nom=$n;
|
||||||
|
$this->taches=$t;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_id(): int {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_nom(): string {
|
||||||
|
return $this->nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_taches(): array {
|
||||||
|
return $this->taches;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("Connection.php");
|
||||||
|
|
||||||
|
class ListeGateway {
|
||||||
|
private $co;
|
||||||
|
|
||||||
|
public function __construct(Connection $co) {
|
||||||
|
$this->co = $co;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getByCreator(int $idUsr) : array {
|
||||||
|
$listes = null;
|
||||||
|
$taches = null;
|
||||||
|
if(!empty($idUsr)){
|
||||||
|
try {
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "SELECT idListe FROM HasList WHERE idUser=:idUser";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
||||||
|
|
||||||
|
$results = $co->getResults();
|
||||||
|
|
||||||
|
Foreach($results as $row){
|
||||||
|
$idListe = $row['idListe'];
|
||||||
|
$queryTaches = "SELECT t.* FROM Tache t, HasTache h WHERE t.id=h.idTache AND h.idListe=:idListe";
|
||||||
|
$co->executeQuery($queryTaches, array(':idListe' => array($idListe, PDO::PARAM_STR)));
|
||||||
|
$resultsTaches = $co->getResults();
|
||||||
|
|
||||||
|
Foreach($resultsTaches as $rowTaches){
|
||||||
|
$taches[] = new Tache($rowTaches['id'], $rowTaches['intitule'], $rowTaches['isCompleted'], $rowTaches['description']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$listes[] = new Liste($row['id'], $row['nom'], $taches);
|
||||||
|
$taches = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception) {
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $listes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function creerTache(int $id, string $intitule, boolean $isCompleted){
|
||||||
|
if(!empty($id) && !empty($intitutle)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "INSERT INTO Tache VALUES (:id, :intitule, :isCompleted)";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':intitule' => array($nom, PDO::PARAM_STR), ':isCompleted' => array($taches, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delTache(int $id){
|
||||||
|
if(!empty($id)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "DELETE FROM Tache WHERE id=:id";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function completeTache(int $id){
|
||||||
|
if(!empty($id)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "UPDATE Tache SET isCompleted=true WHERE id=:id";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
Class Tache {
|
||||||
|
private int $id;
|
||||||
|
private string $intitule;
|
||||||
|
private boolean $isCompleted;
|
||||||
|
private string $description;
|
||||||
|
|
||||||
|
function __construct(int $i, string $in, boolean $is, string $desc){
|
||||||
|
$this->id = $i;
|
||||||
|
$this->intitule = $in;
|
||||||
|
$this->isCompleted = $is;
|
||||||
|
$this->description = $desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_id(): int {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_intitule(): string {
|
||||||
|
return $this->intitule;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_isCompleted(): boolean {
|
||||||
|
return $this->isCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_description(): string {
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("Connection.php");
|
||||||
|
require_once("Utilisateur.php");
|
||||||
|
|
||||||
|
class UserGateway {
|
||||||
|
private $co;
|
||||||
|
|
||||||
|
public function __construct(Connection $co) {
|
||||||
|
$this->co = $co;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function creerUtilisateur(int $id, string $nom, string $pwd){
|
||||||
|
if(!empty($id) && !empty($nom) && empty($password)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "INSERT INTO Utilisateur VALUES (:id, :nom, :pwd)";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
catch(PDOException $Excception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delUtilisateur(int $id){
|
||||||
|
if(!empty($id)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "DELETE FROM Utilisateur WHERE id=:id";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putUtilisateur(Utilisateur $usr){
|
||||||
|
if(!empty($usr.getId()) && !empty($usr.getNom()) && empty($usr.getPassword())){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$updateQuery = "UPDATE Utilisateur SET id=:id AND nom=:nom AND pwd=:pwd";
|
||||||
|
$deleteQuery = "DELETE FROM HasList WHERE user=:id AND liste=:liste";
|
||||||
|
$insertQuery = "INSERT INTO HasList VALUES (:id, :liste)";
|
||||||
|
|
||||||
|
$co->executeQuery($updateQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':nom' => array($usr.getNom(), PDO::PARAM_STR), ':pwd' => array($usr.getPassword(), PDO::PARAM_STR)));
|
||||||
|
foreach($usr.getListListe() as $l){
|
||||||
|
$co->executeQuery($deleteQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':liste' => array($l, PDO::PARAM_STR)));
|
||||||
|
$co->executeQuery($insertQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':liste' => array($l, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(PDOException $Excception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Excception->getMesage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUtilisateurById(int $id) : Utilisateur {
|
||||||
|
$usr = null;
|
||||||
|
if(!empty($id)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "SELECT * FROM Utilisateur WHERE id=:id";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
||||||
|
|
||||||
|
$results = $co->getResults();
|
||||||
|
|
||||||
|
Foreach($results as $row){
|
||||||
|
$usr = new Utilisateur($row['id'], $row['nom'], $row['pwd']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return $usr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUtilisateurbyNameAndPassword(string $nom, string $pwd) : Utilisateur {
|
||||||
|
$usr = null;
|
||||||
|
if(!empty($nom) && !empty($password)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "SELECT * FROM Utilisateur WHERE nom=:nom AND pwd=:pwd";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR)));
|
||||||
|
|
||||||
|
$results = $co->getResults();
|
||||||
|
|
||||||
|
Foreach($results as $row){
|
||||||
|
$usr = new Utilisateur($row['id'], $row['nom'], $row['pwd']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $usr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function creerListe(int $id, string $nom){
|
||||||
|
if(!empty($id) && !empty($nom)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "INSERT INTO Liste VALUES (:id, :nom, :taches)";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':nom' => array($nom, PDO::PARAM_STR), ':taches' => array($taches, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delListe(int $id){
|
||||||
|
if(!empty($id)){
|
||||||
|
try{
|
||||||
|
$co = $this->co;
|
||||||
|
|
||||||
|
$query = "DELETE FROM Tache WHERE id=:id";
|
||||||
|
|
||||||
|
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
catch(PDOException $Exception){
|
||||||
|
echo 'erreur';
|
||||||
|
echo $Exception->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
Class Utilisateur {
|
||||||
|
private int $id;
|
||||||
|
private string $nom;
|
||||||
|
private string $password;
|
||||||
|
private $listListe;
|
||||||
|
|
||||||
|
function __construct(int $i, string $n, string $p, $liste) {
|
||||||
|
$this->id=$i;
|
||||||
|
$this->nom=$n;
|
||||||
|
$this->password=$p;
|
||||||
|
$this->listListe=$liste;
|
||||||
|
}
|
||||||
|
function get_id(): int {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
function get_nom(): string {
|
||||||
|
return $this->nom;
|
||||||
|
}
|
||||||
|
function get_password(): string {
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
|
function get_listListe(){
|
||||||
|
return $this->get_listListe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in new issue