diff --git a/modeles/Connection.php b/modeles/Connection.php new file mode 100644 index 0000000..19ed707 --- /dev/null +++ b/modeles/Connection.php @@ -0,0 +1,34 @@ +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(); + + } + } + +?> \ No newline at end of file diff --git a/modeles/Gateways/ListeGateway.php b/modeles/Gateways/ListeGateway.php new file mode 100644 index 0000000..d082a7a --- /dev/null +++ b/modeles/Gateways/ListeGateway.php @@ -0,0 +1,96 @@ +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(); + } + } + } +} + +?> \ No newline at end of file diff --git a/modeles/Gateways/UserGateway.php b/modeles/Gateways/UserGateway.php new file mode 100644 index 0000000..9dadc5a --- /dev/null +++ b/modeles/Gateways/UserGateway.php @@ -0,0 +1,152 @@ +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(); + } + } + } + +} + +?> \ No newline at end of file diff --git a/modeles/Métier/Liste.php b/modeles/Métier/Liste.php new file mode 100644 index 0000000..10f104f --- /dev/null +++ b/modeles/Métier/Liste.php @@ -0,0 +1,27 @@ +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; + } +} + +?> \ No newline at end of file diff --git a/modeles/Métier/Tache.php b/modeles/Métier/Tache.php new file mode 100644 index 0000000..1e22090 --- /dev/null +++ b/modeles/Métier/Tache.php @@ -0,0 +1,33 @@ +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; + } +} + +?> \ No newline at end of file diff --git a/modeles/Métier/Utilisateur.php b/modeles/Métier/Utilisateur.php new file mode 100644 index 0000000..72bf17f --- /dev/null +++ b/modeles/Métier/Utilisateur.php @@ -0,0 +1,30 @@ +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; + } +} + + +?> \ No newline at end of file diff --git a/modeles/blbl b/modeles/blbl deleted file mode 100644 index e69de29..0000000 diff --git a/userController.php b/userController.php deleted file mode 100644 index 7594872..0000000 --- a/userController.php +++ /dev/null @@ -1,40 +0,0 @@ -action(); - break; - case "connection": - $this->connection(/* valeurs du login et du mdp dans le formulaire */); - break; - }catch(PDOException $e){ - $dataView[]="Erreur inatendue"; - require(__DIR__.'/../vues/erreur.php'); - } - } - } - - public function connection(string $login, string $password){ - - /* Doit faire: - * vider les input du formulaire - * vérifier avec la bd qu'il y a bien un user - */ - - } -} - -?> \ No newline at end of file