diff --git a/DAL/Connection.php b/DAL/Connection.php index b4ce991..1fd9a3c 100644 --- a/DAL/Connection.php +++ b/DAL/Connection.php @@ -3,10 +3,9 @@ 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); +public function __construct(string $dsn, string $username, string $password) { + parent::__construct($dsn,$username,$password); + $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } diff --git a/DAL/gateways/CompteGateway.php b/DAL/gateways/CompteGateway.php index 0e0fad9..6e64dc5 100644 --- a/DAL/gateways/CompteGateway.php +++ b/DAL/gateways/CompteGateway.php @@ -63,27 +63,25 @@ class CompteGateway * Retour : Un tableau contenant tout les compte avec le pseudonyme (devrais avoir une taille entre 0 et 1) * Finalité : Récupérer un Compte en base de données et l'instancier. */ - public function getCompteParPseudo(string $pseudo) : iterable + public function getCompteParPseudo(string $pseudo) : ?Compte { - $gw = new ListeGateway($this->conn()); + $gw = new ListeGateway($this->conn); $requete = "SELECT * FROM _Compte WHERE pseudonyme=:pseudo"; - if(!$this->conn->executeQuerry($requete, [":pseudo" => [$pseudo, PDO::PARAM_STR]])) + if(!$this->conn->executeQuery($requete, [":pseudo" => [$pseudo, PDO::PARAM_STR]])) { return array(); } $comptesSQL = $this->conn->getResults(); - $comptes = array(); - $listes = array(); - - foreach($comptesSQL as $compte) + if(sizeof($comptesSQL) != 0) { - $comptes[] = new Compte( - $compte["pseudonyme"], - $compte["dateCreation"], - $gw->getListeParCreateur($compte["pseudonyme"]), - $compte["motDePasse"], + $compte = new Compte( + $comptesSQL[0]["pseudonyme"], + $comptesSQL[0]["dateCreation"], + $gw->getListeParCreateur(1, 10, $comptesSQL[0]["pseudonyme"]), + $comptesSQL[0]["motDePasse"], ); - return $comptes; + return $compte; } + return null; } } diff --git a/DAL/gateways/ListeGateway.php b/DAL/gateways/ListeGateway.php index 50a5fa7..3a2d49d 100644 --- a/DAL/gateways/ListeGateway.php +++ b/DAL/gateways/ListeGateway.php @@ -31,6 +31,16 @@ class ListeGateway ":createur" => [$l->getCreateur(), PDO::PARAM_STR] ]); } + public function inserer2(string $nom, string $createur) + { + $requette = "INSERT INTO _TodoList(nom, dateCreation, createur) + VALUES(:nom, NOW(), :createur)"; + return $this->conn->executeQuery($requette, [ + ":nom" => [$nom, PDO::PARAM_STR], + ":createur" => [$createur, PDO::PARAM_STR] + ]); + + } /* * Paramètres : l => TodoList à supprimer de la base de données @@ -39,11 +49,18 @@ class ListeGateway */ public function supprimer(TodoList $l) : bool { - $requete = "DELETE FROM _TodoList WHERE listeID=:id"; - return $this->conn->executeQuery($requete,[ + $requette = "DELETE FROM _TodoList WHERE listeID=:id"; + return $this->conn->executeQuery($requette,[ ":id"=>[$l->getID(), PDO::PARAM_INT] ]); } + public function supprimerAvecListID(int $id) + { + $requette = "DELETE FROM _TodoList WHERE listeID=:id"; + return $this->conn->executeQuery($requette, [ + ":id" => [$id, PDO::PARAM_INT] + ]); + } /* * Paramètres : l => TodoList à éditer en base de données @@ -52,14 +69,26 @@ class ListeGateway */ public function modifier(TodoList $l) : bool { - $requete="UPDATE _TodoList SET - nom=:n, public=:p"; - return $this->conn->executeQuery($requete, [ + $requette="UPDATE _TodoList SET + nom=:n WHERE listeID=:id"; + return $this->conn->executeQuery($requette, [ ":n" => [$l->getNom(), PDO::PARAM_STR], + ":id" => [$l->getID(), PDO::PARAM_INT] ]); } + public function modiferNomListe(int $id, string $nom) : bool + { + $requette = "UPDATE _TodoList + SET nom=:n + WHERE listeID=:id"; + return $this->conn->executeQuery($requette, array( + ":n" => [$nom, PDO::PARAM_STR], + ":id" => [$id, PDO::PARAM_INT] + )); + } + /* * Paramètres : page => Numéro de la page à afficher * nbTache => Nombre de tâches à afficher par pages @@ -99,7 +128,7 @@ class ListeGateway * nbTache => Nombre de tâches à afficher par pages * Retour : Retourne un tableau de listes de taille maximale ordoné par nom de liste (ordre lexicographique) * Finalité : Récuperer les todoLists en bases de données par ordre de lexicographique et les instancier - */ + */ public function listeParNom(int $page, int $nbListes) : iterable { $gwTache = new TacheGateway($this->conn); @@ -140,10 +169,10 @@ class ListeGateway { $gwTache = new TacheGateway($this->conn); $lites = array(); - $requete = "SELECT * FROM _TodoList WHERE Createur = :c LIMIT :p+:n, :n"; + $requete = "SELECT * FROM _TodoList WHERE Createur = :c LIMIT :p, :n"; $isOK=$this->conn->executeQuery($requete, [ ":c" => [$createur, PDO::PARAM_STR], - ":p" => [$page-1, PDO::PARAM_INT], + ":p" => [($page-1)*$nbListes, PDO::PARAM_INT], ":n" => [$nbListes, PDO::PARAM_INT] ]); if(!$isOK) @@ -152,7 +181,7 @@ class ListeGateway } $res = $this->conn->getResults(); - + $listes = array(); foreach($res as $liste) { $listes[] = new TodoList( diff --git a/DAL/gateways/TacheGateway.php b/DAL/gateways/TacheGateway.php index ecfd604..ccde1f7 100644 --- a/DAL/gateways/TacheGateway.php +++ b/DAL/gateways/TacheGateway.php @@ -33,6 +33,22 @@ class TacheGateway ]); } + public function insererSimple(string $nom, string $comm, int $id) : bool + { + $requette = "INSERT INTO _Tache(NomTache, TacheFaite, Commentaire, listID) VALUES( + :nom, :fait, :commentaire, :id + )"; + + return $this->conn->executeQuery($requette, [ + ":nom" => [$nom, PDO::PARAM_STR], + ":fait"=> [false, PDO::PARAM_BOOL], + ":commentaire" => [$comm, PDO::PARAM_STR], + ":id" => [$id, PDO::PARAM_INT] + + ]); + + } + /* * Paramètre : tacheAModifier => Tache à éditer en base de données * Retour : True si la requete c'est correctement éxécuter. Sinon false @@ -47,12 +63,35 @@ class TacheGateway WHERE tacheID = :id"; return $this->conn->executeQuery($requette,[ - ':nom' => [$tacheAModifier->nom, PDO::PRAM_STR], - ':commentaire' => [$tacheAModifier->commentaire, PDO::PARAM_STR], - ':fait' => [$tacheAModifier->estFait, PDO::PARAM_BOOL] + ':nom' => [$tacheAModifier->getNom(), PDO::PRAM_STR], + ':commentaire' => [$tacheAModifier->getCommentaire(), PDO::PARAM_STR], + ':fait' => [$tacheAModifier->estFait(), PDO::PARAM_BOOL] ]); } + public function modifierDoneTache(int $idTache, bool $done) + { + $requette = "UPDATE _Tache SET + TacheFaite = :d + WHERE + tacheID = :id"; + return $this->conn->executeQuery($requette, array( + ":d" => [$done, PDO::PARAM_BOOL], + ":id" => [$idTache, PDO::PARAM_INT] + )); + } + public function modifierNomCommTache(int $id, string $nom, string $comm) + { + $requette = "UPDATE _Tache + SET NomTache = :n, Commentaire = :c + WHERE tacheID = :id"; + return $this->conn->executeQuery($requette, array( + ":n" => [$nom, PDO::PARAM_STR], + ":c" => [$comm, PDO::PARAM_STR], + ":id" => [$id, PDO::PARAM_INT] + )); + } + /* * Paramètre : tacheASupprimer => Tache à supprimer en base de données * Retour : True si la requete c'est correctement éxécuter. Sinon false @@ -62,11 +101,19 @@ class TacheGateway { $requette = "DELETE FROM _Tache WHERE tacheID=:id"; return $this->conn->executeQuery($requette, - [':id', [$tacheASupprimer->tacheID]] + [':id', [$tacheASupprimer->tacheID, PDO::PARAM_INT]] ); } + public function supprimerAvecTacheID(int $id) + { + $requette = "DELETE FROM _Tache WHERE tacheID=:id"; + return $this->conn->executeQuery($requette,[ + ':id' => [$id, PDO::PARAM_INT] + ]); + } + /* * Paramètre : l => Identifiant de la TodoList. * page => Numéro de la page à retourner @@ -76,10 +123,10 @@ class TacheGateway */ public function getTachesParIDListe(int $l, int $page, int $nbTache) : iterable { - $requete = "SELECT * FROM _Tache WHERE listID=:id ORDER BY NomTache LIMIT :p+:n, :n"; + $requete = "SELECT * FROM _Tache WHERE listID=:id ORDER BY NomTache LIMIT :p, :n"; if(!$this->conn->executeQuery($requete,[ - ":id" => [$l->getID(), PDO::PARAM_INT], - ":p" => [$page-1, PDO::PARAM_INT], + ":id" => [$l, PDO::PARAM_INT], + ":p" => [($page-1)*$nbTache, PDO::PARAM_INT], ":n" => [$nbTache, PDO::PARAM_INT] ])) { @@ -99,4 +146,18 @@ class TacheGateway } return $taches; } + + public function getListeParIDTache(?int $tache) //: ?int + { + if(is_null($tache)) + { + throw new Exception("Le numero de tache ne doit pas être === à null"); + } + $requette = "SELECT listID FROM _Tache WHERE tacheID = :id"; + if(!$this->conn->executeQuery($requette, array(":id"=>[$tache, PDO::PARAM_INT]))) + { + throw new Exception("Problème lors de la récupération de la liste de la tache $tache"); + } + return $this->conn->getResults()[0][0]; + } } diff --git a/config/Validation.php b/config/Validation.php index f6bc5b4..c302f55 100644 --- a/config/Validation.php +++ b/config/Validation.php @@ -2,13 +2,9 @@ class Validation { - public static function netoyerNomTache(string $nom) : ?string + public static function netoyerString(?string $str) : ?string { - return filter_var($nom, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE); - } - public static function netoyerCommentaireTache(string $comm) : ?string - { - return filter_var($comm, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE); + return filter_var($str, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE); } public static function validerEffectuationTache($estFait) : bool { @@ -17,8 +13,8 @@ class Validation public static function netoyerEtValiderTache(string $nom, string $comm, bool $estFait) { - $nom = self::netoyerNomTache($nom); - $comm = self::netoyerCommentaireTache($comm); + $nom = self::netoyerString($nom); + $comm = self::netoyerString($comm); $estFaitValide = self::validerEffectuationTache($estFait); if($nom == null || $comm == null || !$estFaitValide) @@ -33,8 +29,13 @@ class Validation ); } - public static function validerUnIntSuperieurZero($int) + public static function validerUnIntSupperieurZero($int) { return filter_var($int, FILTER_VALIDATE_INT, array("min_range"=>1)); } + + public static function validerNomTiretNum($valeur, $nom) + { + return filter_var($valeur, FILTER_VALIDATE_REGEXP, array("option" => array("regexp" => "$name-[1-9][0-9]+$"))); + } } diff --git a/config/dsn.php b/config/dsn.php index f3c1c6a..1bd17ea 100644 --- a/config/dsn.php +++ b/config/dsn.php @@ -1,5 +1,10 @@ Reinit(); + break; + case "connection": + if(!isset($_POST["pseudonyme"]) || !isset($_POST["motDePasse"])) + { + $erreurs[] = "Erreur lors de la transmission des informations de connections"; + throw new Exception(); + } + + $login = Validation::netoyerString($_POST["pseudonyme"]); + $mdp = Validation::netoyerString($_POST["motDePasse"]); + + if(is_null($login) || is_null($mdp)) + { + throw new ValueError("Le login ou le mot de passe contient des valeurs illégales"); + } + + $compte = $this->connection($_POST["pseudonyme"], $_POST["motDePasse"]); + if(!is_null($compte)) + { + header("Location: ?action=seeLists"); + } + else + { + header("Location: ?action=GloubiBoulga"); + } + break; + case "SeConnecter": + default: + require("vues/connection.php"); + break; + } + }catch(PDOException $e) + { + //si erreur BD, pas le cas ici + $ereurs[] = "Erreur inattendue!!! "; + require("vues/erreur.php"); + } + catch (Exception $e2) + { + $erreurs[] = $e2->getMessage(); + require("vues/erreur.php"); + } + exit(0); + } + + function Reinit() { + global $rep,$vues; // nécessaire pour utiliser variables globales + require("vues/connection.php"); + } + + function connection(string $login, string $mdp) : Compte + { + $mdl = new ModelConnecte(); + $compte = $mdl->connection($login, $mdp); + return $compte; + } +} diff --git a/controleur/ControleurConnecte.php b/controleur/ControleurConnecte.php new file mode 100644 index 0000000..d1c527d --- /dev/null +++ b/controleur/ControleurConnecte.php @@ -0,0 +1,448 @@ +Reinit(); + break; + case "seeLists": + $this->seeLists(); + break; + case "seeList": + $this->seeList(); + break; + case "supprimerListe": + $this->supprimerListe(); + break; + case "wantAddList": + $this->wantAddList(); + break; + case "addList": + $this->addList(); + break; + case "modifyList": + $this->modifyList(); + break; + case "setTacheFait": + $this->editDone(); + break; + case "editionTache": + $this->editionTache(); + break; + case "wantAddTask": + $this->wantAddTask(); + break; + case "addTask": + $this->addTask(); + break; + case "delTask": + $this->delTask(); + break; + case "logout": + $this->logout(); + break; + case "veuxModifierListe": + $this->veuxModifierListe(); + break; + case "veuxModifierTache": + $this->veuxModifierTache(); + break; + default: + echo "Default"; + /* + $dVueEreur[] = "Erreur d'appel php"; + require ($rep.$vues['vuephp1']); + */ + break; + } + }catch(PDOException $e) + { + //si erreur BD, pas le cas ici + echo "Erreur PDO"; + $erreurs[] =$e->getMessage(); + require ("vues/erreur.php"); + } + catch (Exception $e2) + { + $erreurs[] =$e2->getMessage(); + require ("vues/erreur.php"); + } + // exit(0); + } + + function Reinit() { + global $rep,$vues; // nécessaire pour utiliser variables globales + require ($rep.$vues['connection']); + } + + function seeLists() + { + if(!isset($_GET["page"]) || empty($_GET["page"])) + { + $page = 1; + } + else + { + $page = Validation::validerUnIntSuperieurZero($_GET["page"]) ? $_GET["page"] : 1; + } + + if(!isset($_GET["nbElements"]) || empty($_GET["nbElements"])) + { + $nbElements = 10; + } + else + { + $nbElements = Validation::validerUnIntSuperieurZero($_GET["nbElements"]) ? $_GET["nbElements"] : 10; + } + + $mdl = new ModelConnecte(); + $todoLists = $mdl->getLists($_SESSION["login"], $page, $nbElements); + require("vues/accueil.php"); + } + + function seeList() + { + if(!isset($_REQUEST["list"]) || empty($_REQUEST["list"])) + { + throw new Exception("Aucune liste n'est demendée"); + } + + if(!Validation::validerUnIntSupperieurZero($_REQUEST["list"])) + { + throw new Exception("Valeur illégale de la liste requétée"); + } + $mdl = new ModelConnecte(); + $taches = $mdl->getTaches($_REQUEST["list"]); + $actualList = $_REQUEST["list"]; + require("vues/editeurDeStatuts.php"); + } + + function editDone() + { + if(isset($_REQUEST["estFait"])) + { + if(!is_array($_REQUEST["estFait"])) + { + throw new Exception("La liste des taches faites doit être un tableau."); + } + } + if(!isset($_REQUEST["exist"])) + { + throw new Exception("Aucune tâche n'est définit"); + } + if(!is_array($_REQUEST["exist"])) + { + throw new Exception("La liste des taches doit être un tableau."); + } + $mdl = new ModelConnecte(); + $mdl->setDoneTaches(); + new ControleurConnecte(); + } + + function wantAddList() + { + require("vues/ajouterListe.php"); + } + + function addList() + { + if(!isset($_REQUEST["nomNouvelleListe"])) + { + throw new Exception("La nouvelle liste doit avoir un nom!"); + } + if(empty($_REQUEST["nomNouvelleListe"])) + { + throw new Exception("La nouvelle liste doit avoir un nom!"); + } + $nom = Validation::netoyerString($_REQUEST["nomNouvelleListe"]); + if(is_null($nom)) + { + throw new Exception("Le nom de la nouvelle liste contien un ou plusieurs caractères illégales."); + } + $mdl = new ModelConnecte(); + $mdl->createTodoList($nom); + $_REQUEST["action"] = "seeLists"; + new ControleurConnecte(); + } + + function wantAddTask() + { + $mdl = new ModelConnecte(); + if(!$mdl->estConnecte()) + { + throw new Exception("Permission non suffisantes pour effectuer cette action!"); + } + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le numero de liste doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le numero de liste doit être définit"); + } + $actualList = Validation::validerUnIntSupperieurZero($_REQUEST["list"]) ? $_REQUEST["list"] : null; + if(is_null($actualList)) + { + throw new Exception("Le numero de liste doui être un entier supperieur à 0"); + } + require("vues/addTask.php"); + } + function addTask() + { + $mdl = new ModelConnecte(); + if(!$mdl->estConnecte()) + { + throw new Exception("Permission non suffisantes pour effectuer cette action!"); + } + + if(!isset($_REQUEST["nomTache"])) + { + throw new Exception("Le nom de la novelle tache est introuvable (?o?)'"); + } + if(empty($_REQUEST["nomTache"])) + { + throw new Exception("Le nom de la nouvelle tache ne doit pas être vide"); + } + if(!isset($_REQUEST["commentaireTache"])) + { + throw new Exception("Le commentaire de la tache est introuvable!"); + } + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le numero de liste doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le numero de liste doit être définit"); + } + $list = Validation::validerUnIntSupperieurZero($_REQUEST["list"]) ? $_REQUEST["list"] : null; + $nom = Validation::netoyerString($_REQUEST["nomTache"]); + $comm = Validation::netoyerString($_REQUEST["commentaireTache"]); + if(is_null($nom) || is_null($comm) || is_null($list)) + { + throw new Exception("Le nom, la liste ou le commentaire de la nouvelle tache contiennent des caractèrent illégales!"); + } + $mdl->createTask($nom, $comm, $list); + $_REQUEST["action"] = "seeList"; + $_REQUEST["list"] = $list; + new ControleurConnecte(); + + } + + function supprimerListe() + { + $mdl = new ModelConnecte(); + if(!$mdl->estConnecte()) + { + throw new Exception("Permission non suffisantes pour effectuer cette action!"); + } + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le paramètre list doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit être un entier strictement superieur à 0"); + } + $mdl->supprimerListe($_REQUEST["list"]); + $_REQUEST["action"] = "seeLists"; + new ControleurConnecte(); + } + + function delTask() + { + $mdl = new ModelConnecte(); + if(!$mdl->estConnecte()) + { + throw new Exception("Permission non suffisantes pour effectuer cette action!"); + } + if(!isset($_REQUEST["task"])) + { + throw new Exception("Le parametre task doit exister"); + } + if(empty($_REQUEST["task"])) + { + throw new Exception("Le paramètre task doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["task"])) + { + throw new Exception("Le parametre task doit être un entier strictement superieur à 0"); + } + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le paramètre list doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit être un entier strictement superieur à 0"); + } + $mdl->delTask($_REQUEST["task"]); + $_REQUEST["action"] = "seeList"; + new ControleurConnecte(); + } + function logout() + { + $mdl = new ModelConnecte(); + $mdl->destroySession(); + new ControleurCommun(); + } + function veuxModifierListe() + { + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le paramètre list doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit être un entier strictement superieur à 0"); + } + $listeAModifier = $_REQUEST["list"]; + require("vues/editeurDeListe.php"); + } + function modifyList() + { + $mdl = new ModelConnecte(); + if(!$mdl->estConnecte()) + { + throw new Exception("Permission non suffisantes pour effectuer cette action!"); + } + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le paramètre list doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit être un entier strictement superieur à 0"); + } + if(!isset($_REQUEST["nouveauNom"])) + { + throw new Exception("Le parametre nouveauNom doit exister"); + } + if(empty($_REQUEST["nouveauNom"])) + { + throw new Exception("Le paramètre nouveauNom doit contenire une valeur"); + } + $nouveauNom = Validation::netoyerString($_REQUEST["nouveauNom"]); + if(is_null($nouveauNom)) + { + throw new Exception("Le nouveau nom contient des caractères illégeaux"); + } + $mdl->modifierNomListe($_REQUEST["list"], $nouveauNom); + $_REQUEST["action"] = "seeLists"; + new ControleurConnecte(); + } + function veuxModifierTache() + { + if(!isset($_REQUEST["task"])) + { + throw new Exception("Le parametre task doit exister"); + } + if(empty($_REQUEST["task"])) + { + throw new Exception("Le paramètre task doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["task"])) + { + throw new Exception("Le parametre task doit être un entier strictement superieur à 0"); + } + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le paramètre list doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit être un entier strictement superieur à 0"); + } + $tacheAModifier = $_REQUEST["task"]; + $listeAModifier = $_REQUEST["list"]; + require("vues/editeurDeTache.php"); + } + function editionTache() + { + $mdl = new ModelConnecte(); + if(!$mdl->estConnecte()) + { + throw new Exception("Permission non suffisantes pour effectuer cette action!"); + } + if(!isset($_REQUEST["task"])) + { + throw new Exception("Le parametre task doit exister"); + } + if(empty($_REQUEST["task"])) + { + throw new Exception("Le paramètre task doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["task"])) + { + throw new Exception("Le parametre task doit être un entier strictement superieur à 0"); + } + if(!isset($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit exister"); + } + if(empty($_REQUEST["list"])) + { + throw new Exception("Le paramètre list doit contenire une valeur"); + } + if(!Validation::validerUnIntSupperieurZero($_REQUEST["list"])) + { + throw new Exception("Le parametre list doit être un entier strictement superieur à 0"); + } + if(!isset($_REQUEST["nom"])) + { + throw new Exception("Le parametre nom doit exister"); + } + if(empty($_REQUEST["nom"])) + { + throw new Exception("Le paramètre nom doit contenire une valeur"); + } + if(!isset($_REQUEST["commentaire"])) + { + throw new Exception("Le parametre commentaire doit exister"); + } + $nom = Validation::netoyerString($_REQUEST["nom"]); + $comm = Validation::netoyerString($_REQUEST["commentaire"]); + if(is_null($nom) || is_null($comm)) + { + throw new Exception("Le nom ou le commentaire contien des valeurs illégales"); + } + $mdl->modifierNomCommTache($_REQUEST["task"], $nom, $comm); + $list = $_REQUEST["list"]; + $_REQUEST["action"] = "seeList"; + new ControleurConnecte(); + } +} diff --git a/documentation/DiagrameDeClasse.dia b/documentation/DiagrameDeClasse.dia new file mode 100644 index 0000000..94b402d Binary files /dev/null and b/documentation/DiagrameDeClasse.dia differ diff --git a/données/faussesDonnées.php b/données/faussesDonnées.php new file mode 100644 index 0000000..d32b021 --- /dev/null +++ b/données/faussesDonnées.php @@ -0,0 +1,20 @@ + [ + "addList", "setTacheFait", "editionTache", "déconéction", "seeLists", + "seeList", "wantAddList", "wantAddTask", "addTask", "supprimerListe", + "delTask", "logout", "veuxModifierListe", "modifyList", "veuxModifierTache"], + "Visiteur" => ["seConnceter", "connection"] + ); + + public function start() + { + session_start(); + $modelCompte = new ModelConnecte(); + $connecte = $modelCompte->estConnecte(); + $action = Validation::netoyerString(isset($_GET["action"]) ? $_GET["action"] : ""); + if(in_array($action, $this->actions["Compte"])) + { + if(!$connecte) + { + require("vues/connection.php"); + }else + { + $controler = new controleurConnecte(); + } + } + else + { + if(!$connecte) + { + $controler = new controleurCommun(); + } + else + { + $_REQUEST["action"] = "seeLists"; + new ControleurConnecte(); + } + } + } +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..6f3868a --- /dev/null +++ b/index.php @@ -0,0 +1,10 @@ + + +start(); + #$controler = new ControleurCommun(); + + ?> + diff --git a/metier/Tache.php b/metier/Tache.php index 872875c..1825a2d 100644 --- a/metier/Tache.php +++ b/metier/Tache.php @@ -8,7 +8,7 @@ class Tache private $tacheID; // Constructeur - public function __construct(string $nom, bool $estFait=false, string $commentaire="", int $tacheID) + public function __construct(string $nom, bool $estFait=false, ?string $commentaire="", int $tacheID) { $this->nom = $nom; $this->fait = $estFait; @@ -28,7 +28,7 @@ class Tache $this->nom = $nouveauNom; } - public function getCommentaire() : string + public function getCommentaire() : ?string { return $this->commentaire; } diff --git a/modeles/ModelConnecte.php b/modeles/ModelConnecte.php new file mode 100644 index 0000000..a2a0852 --- /dev/null +++ b/modeles/ModelConnecte.php @@ -0,0 +1,130 @@ +getCompteParPseudo($login); + if($compte == null) + { + throw new Exception("Le login ou le mot de passe est incorecte"); + } + if(!password_verify($mdp, $compte->getMotDePasse())) + { + throw new Exception("Le login ou le mot de passe est incorecte"); + } + $_SESSION["login"] = $compte->getPseudonyme(); + $_SESSION["Lists"] = $compte->getListes(); + return $compte; + } + + public function estConnecte() : bool + { + if(isset($_SESSION["login"]) && !empty($_SESSION["login"])) + { + return true; + } + return false; + } + + public function getLists(string $pseudo, int $page, int $nbElements) + { + global $dsn, $loginDB, $pswdDB; + $gw = new ListeGateway(new Connection($dsn, $loginDB, $pswdDB)); + return $gw->getListeParCreateur($page, $nbElements, $pseudo); + } + + public function getTaches(int $liste) + { + global $dsn, $loginDB, $pswdDB; + $gw = new TacheGateway(new Connection($dsn, $loginDB, $pswdDB)); + return $taches = $gw->getTachesParIDListe($liste, 1, 10); + } + + public function setDoneTaches() + { + global $dsn, $loginDB, $pswdDB; + $gw = new TacheGateway(new Connection($dsn, $loginDB, $pswdDB)); + $tacheID = null; + foreach($_REQUEST["exist"] as $tache) + { + if(in_array($tache, isset($_REQUEST["estFait"])?$_REQUEST["estFait"]:array() )) + { + if(!$gw->modifierDoneTache($tache, true)) + { + throw new Exception("Erreur lors de la modification du statut de la tache $tache"); + } + }else + { + if(!$gw->modifierDoneTache($tache, false)) + { + throw new Exception("Erreur lors de la modification du statut de la tache $tache"); + } + } + $tacheID = $tache; + } + $_REQUEST["action"] = "seeList"; + $_REQUEST["list"] = $gw->getListeParIDTache($tacheID); + } + public function createTodoList(string $nom) + { + global $dsn, $loginDB, $pswdDB; + $gw = new ListeGateway(new Connection($dsn, $loginDB, $pswdDB)); + if(!$this->estConnecte()) + { + throw new Exception("Il faut être connecté.e pour créer un Todo List."); + } + $pseudo = Validation::netoyerString($_SESSION["login"]); + if(is_null($pseudo)) + { + throw new Exception("Erreur avec la valeur enregistré du pseudonyme"); + } + $gw->inserer2($nom, $pseudo); + } + public function createTask(string $nom, string $comm, int $list) + { + global $dsn, $loginDB, $pswdDB; + $gw = new TacheGateway(new Connection($dsn, $loginDB, $pswdDB)); + if(!$gw->insererSimple($nom, $comm, $list)) + { + throw new Exception("Erreur lors de la création de la tache"); + } + } + public function supprimerListe(int $listID) : bool + { + global $dsn, $loginDB, $pswdDB; + $gw = new ListeGateway(new Connection($dsn, $loginDB, $pswdDB)); + return $gw->supprimerAvecListID($listID); + } + public function delTask(int $id) : bool + { + global $dsn, $loginDB, $pswdDB; + $gw = new TacheGateway(new Connection($dsn, $loginDB, $pswdDB)); + return $gw->supprimerAvecTacheID($id); + } + public function destroySession() + { + session_unset(); + session_destroy(); + $_SESSION = array(); + } + public function modifierNomListe(int $idListe, string $nouveauNom) + { + global $dsn, $loginDB, $pswdDB; + $gw = new ListeGateway(new Connection($dsn, $loginDB, $pswdDB)); + return $gw->modiferNomListe($idListe, $nouveauNom); + } + public function modifierNomCommTache(int $idTache, string $nom, string $comm) + { + global $dsn, $loginDB, $pswdDB; + $gw = new TacheGateway(new Connection($dsn, $loginDB, $pswdDB)); + return $gw->modifierNomCommTache($idTache, $nom, $comm); + } + +} diff --git a/modeles/ModelPrincipal.php b/modeles/ModelPrincipal.php new file mode 100644 index 0000000..3d25343 --- /dev/null +++ b/modeles/ModelPrincipal.php @@ -0,0 +1,5 @@ + - <?=$nomDuSite?> + Accueil @@ -15,17 +15,21 @@ créateur date de création supprimer + mofifier - - - getNom()?> - getCreateur()?> - getDateCreation()?> - A remplacer par un image de poubelle (^u^)' - - + + + + getNom()?> + getCreateur()?> + getDateCreation()?> + A remplacer par un image de poubelle (^u^)' + A remplacer par un image de stylo (^u^") + + + diff --git a/vues/addTask.php b/vues/addTask.php new file mode 100644 index 0000000..8c0453e --- /dev/null +++ b/vues/addTask.php @@ -0,0 +1,36 @@ + + + + Ajouter une tache + + + + + +
+ +
+ +
+
"> +
+ + + + + + + + + + + + + +
NomCommentaire
+ + + + + + diff --git a/vues/ajouterListe.php b/vues/ajouterListe.php index a407ac6..d24d4fb 100644 --- a/vues/ajouterListe.php +++ b/vues/ajouterListe.php @@ -1,7 +1,7 @@ - <?=$nomDuSite?> + Ajouter une liste diff --git a/vues/connection.php b/vues/connection.php index bdf3844..bf2bd2f 100644 --- a/vues/connection.php +++ b/vues/connection.php @@ -8,7 +8,7 @@

Se Connecter

-
+ diff --git a/vues/editeurDeListe.php b/vues/editeurDeListe.php new file mode 100644 index 0000000..dc76033 --- /dev/null +++ b/vues/editeurDeListe.php @@ -0,0 +1,34 @@ + + + + Éditer une liste + + + + + +
+ +
+ +
+ "> +
+ + + + + + + + + + + +
Tâche
+ + +
+
+ + diff --git a/vues/editeurDeStatuts.php b/vues/editeurDeStatuts.php index 4dc09a9..53098f6 100644 --- a/vues/editeurDeStatuts.php +++ b/vues/editeurDeStatuts.php @@ -1,8 +1,9 @@ - <?=$nomDuSite?> + Visualisation d'une liste + @@ -12,28 +13,40 @@
-
+ + + - - - - - - - + + + + + + + + + + + + + + + + +
Fait Tâche CommentaireSupprimerModifer
estFait() ? "checked" : ""?>/>getNom()?>getCommentaire()?>
estFait() ? "checked" : ""?>/>getNom()?>getCommentaire()?>À remplacer par une image de poubelle (^u^)"À remplacer par une image de stylo (^u^")
+
- - + +
diff --git a/vues/editeurDeTache.php b/vues/editeurDeTache.php index 17ae919..41ec3bf 100644 --- a/vues/editeurDeTache.php +++ b/vues/editeurDeTache.php @@ -1,7 +1,7 @@ - <?=$nomDuSite?> + Éditer une tache @@ -12,7 +12,7 @@
-
+ &list="> @@ -22,16 +22,14 @@ - - - - - - + + + +
- - + +
diff --git a/vues/erreur.php b/vues/erreur.php index 6a0422f..a810216 100644 --- a/vues/erreur.php +++ b/vues/erreur.php @@ -3,19 +3,18 @@ ERREUR :/ + - - $commentaire) :?> + - diff --git a/vues/header.php b/vues/header.php index 2551c67..13195ca 100644 --- a/vues/header.php +++ b/vues/header.php @@ -1,14 +1,14 @@ -
ErreurCommentaire