From a4f871e5d75f25139661970a2b2e64d113defee1 Mon Sep 17 00:00:00 2001 From: Lucie Bedouret Date: Wed, 14 Dec 2022 13:20:10 +0100 Subject: [PATCH] ADD: tout ce qui est demander --- config/config.php | 2 + controleurs/ControleurUtilisateur.php | 2 +- controleurs/ControleurVisiteur.php | 84 ++++++++++++++---- controleurs/FrontControleur.php | 2 +- modeles/Gateways/ListeGateway.php | 119 ++++++++++++++++++-------- modeles/Modele/ListModel.php | 23 ++++- vues/acceuil.php | 17 ++-- vues/connection.php | 4 + vues/creationListe.php | 4 +- vues/creationTache.php | 15 ++++ vues/infosListe.php | 64 ++++++++++++++ vues/listesPrivees.php | 28 +++--- vues/profile.php | 14 +-- 13 files changed, 292 insertions(+), 86 deletions(-) create mode 100644 vues/creationTache.php create mode 100644 vues/infosListe.php diff --git a/config/config.php b/config/config.php index b2c1b84..93f2fab 100644 --- a/config/config.php +++ b/config/config.php @@ -14,6 +14,8 @@ $vues['inscription']='vues/inscription.php'; $vues['profile']='vues/profile.php'; $vues['listesPrivees']='vues/listesPrivees.php'; $vues['creationListe']='vues/creationListe.php'; +$vues['infosListe']='vues/infosListe.php'; +$vues['creationTache']='vues/creationTache.php'; // Styles $styles['commun']='vues/styles/commonStyles.css'; $styles['connection']='vues/styles/connectionStyle.css'; diff --git a/controleurs/ControleurUtilisateur.php b/controleurs/ControleurUtilisateur.php index 1483345..fa4e665 100644 --- a/controleurs/ControleurUtilisateur.php +++ b/controleurs/ControleurUtilisateur.php @@ -3,7 +3,7 @@ class ControleurUtilisateur{ function __construct() { - global $rep,$vues, $dataView; + global $rep,$vues, $dataView,$styles,$assets; $arrayErrorViews= array(); $action = $_REQUEST['action']??null; diff --git a/controleurs/ControleurVisiteur.php b/controleurs/ControleurVisiteur.php index c07f498..a31b439 100644 --- a/controleurs/ControleurVisiteur.php +++ b/controleurs/ControleurVisiteur.php @@ -3,7 +3,7 @@ class ControleurVisiteur { public function __construct() { - global $rep,$vues,$styles,$assets; + global $rep,$vues,$dataView,$styles,$assets; $arrayErrorViews= array(); try{ $action = $_REQUEST['action']??null; @@ -11,6 +11,9 @@ class ControleurVisiteur { case NULL: $this->reinit(); break; + case "goHome": + $this->reinit(); + break; case 'accessConnectionPage': require($rep.$vues['connection']); break; @@ -20,6 +23,22 @@ class ControleurVisiteur { case "accessCreationListePage": require($rep.$vues['creationListe']); break; + case "accessCreationTachePage": + $dataView=$_POST['liste']; + require($rep.$vues['creationTache']); + break; + case "addTache": + $this->addTache($arrayErrorViews); + break; + case "accessListInfos": + $this->accessListInfos($arrayErrorViews); + break; + case "delTache": + $this->delTache($arrayErrorViews); + break; + case "changeCompletedTache": + $this->changeCompletedTache($arrayErrorViews); + break; case "connection": $this->connection($arrayErrorViews); break; @@ -28,17 +47,9 @@ class ControleurVisiteur { case "creerListe": $this->creerListe($arrayErrorViews); break; - case "supprListe": - $this->supprListe($arrayErrorViews); + case "delListe": + $this->delListe($arrayErrorViews); break; - case "creerTache": - $this->creerTache($arrayErrorViews); - break; - case "cocherTache": - $this->cocherTache($arrayErrorViews); - break; - case "supprTache": - $this->supprTache($arrayErrorViews); default : $arrayErrorViews[]="Erreur innatendue !!!"; require($rep.$vues['acceuil']); @@ -58,6 +69,42 @@ class ControleurVisiteur { } + public function accessListInfos($arrayErrorViews){ + global $rep,$vues,$dataView; + $idListe=$_POST['liste']; + $model = new ListeModel(); + $dataView = $model->pullListById($idListe); + require($rep.$vues['infosListe']); + } + + public function addTache($arrayErrorViews){ + global $rep,$vues,$dataView; + $nom=$_POST['name']; + $idListe=$_POST['liste']; + $model = new ListeModel(); + $model->addTache($nom,$idListe); + $_REQUEST['action']="accessListInfos"; + $this->accessListInfos($arrayErrorViews); + } + + public function delTache($arrayErrorViews){ + global $rep,$vues,$dataView; + $idTache=$_POST['tache']; + $model= new ListeModel(); + $model->delTache($idTache); + $_REQUEST['action']="accessListInfos"; + $this->accessListInfos($arrayErrorViews); + } + + public function changeCompletedTache($arrayErrorViews){ + global $rep,$vues,$dataView; + $idTache=$_POST['tache']; + $model = new ListeModel(); + $model->changeCompletedTache($idTache); + $_REQUEST['action']="accessListInfos"; + $this->accessListInfos($arrayErrorViews); + } + public function connection(array $vues_erreur){ global $rep,$vues,$dataView; $usrname=$_POST['login']; @@ -102,10 +149,8 @@ class ControleurVisiteur { $nom=$_POST['name']; $model = new ListeModel(); if(isset($_SESSION['login'])){ - foreach($_POST['private'] as $valeur){ - $private=$valeur; - $model->creerListe($nom,$private); - } + $private=$_POST['private']; + $model->creerListe($nom,$private); } else{ $model->creerListe($nom,null); @@ -114,12 +159,13 @@ class ControleurVisiteur { $this->reinit(); } - public function supprListe(array $vues_erreur){ + public function delListe(array $vues_erreur){ global $rep, $vues; - require($rep.$vues['suppressionListe']); - + $idListe=$_POST['liste']; $model = new ListeModel(); - $model->supprListe(); + $model->delListe($idListe); + $_REQUEST['action']=null; + $this->reinit(); } public function creerTache(array $vues_erreur){ diff --git a/controleurs/FrontControleur.php b/controleurs/FrontControleur.php index f0e4af6..d03e037 100644 --- a/controleurs/FrontControleur.php +++ b/controleurs/FrontControleur.php @@ -4,7 +4,7 @@ class FrontControleur{ public function __construct(){ $liste_actions_utilisateur = array('accessPrivateLists','accessProfilePage','deconnection','crerListePv','desinscription','changerPassword'); - $liste_actions_visiteur = array('accessCreationListePage','accessInscription','accessConnectionPage','creerListe','suprrListe','connection','inscription','creerTache','cocherTache','supprTache'); + $liste_actions_visiteur = array('goHome','changeCompletedTache','accessCreationTachePage','addTache','delTache','accessListInfos','accessCreationListePage','accessInscription','accessConnectionPage','creerListe','delListe','connection','inscription'); global $rep,$vues,$bd,$dataView,$styles,$assets; session_start(); try{ diff --git a/modeles/Gateways/ListeGateway.php b/modeles/Gateways/ListeGateway.php index 30c9c11..4529a5f 100644 --- a/modeles/Gateways/ListeGateway.php +++ b/modeles/Gateways/ListeGateway.php @@ -87,44 +87,74 @@ class ListeGateway { return $listes; } - public function creerTache(string $intitule){ - if(!empty($id) && !empty($intitutle)){ - try{ - $co = $this->co; + public function getById($id){ + $taches=null; + $liste=null; + $co = $this->co; + $query = "SELECT * FROM Liste WHERE id=:id"; + + $co->executeQuery($query, array('id' => array($id, PDO::PARAM_INT))); + + $results = $co->getResults(); + foreach ($results as $row){ + $idListe = $row['id']; + $queryTaches = "SELECT * FROM Tache WHERE idListe=:id"; + $co->executeQuery($queryTaches, array(':id' => array($idListe, PDO::PARAM_INT))); + $resultsTaches = $co->getResults(); + + foreach($resultsTaches as $rowTaches){ + if($rowTaches['complete']=="0"){ + $taches[] = new Tache($rowTaches['id'], $rowTaches['nom'],false,$idListe); + }else{ + $taches[] = new Tache($rowTaches['id'], $rowTaches['nom'],true,$idListe); + } + + } - $query = "INSERT INTO Tache VALUES (NULL, :intitule, 0)"; + $liste = new Liste($row['id'], $row['nom'],$row['nomCreateur'], $taches); + } + return $liste; + } - $co->executeQuery($query, array(':intitule' => array($nom, PDO::PARAM_STR))); - } - catch(PDOException $Exception){ - echo 'erreur'; - echo $Exception->getMessage(); - } + public function creerTache(string $nom, int $idListe){ + try{ + $co = $this->co; + + $query = "INSERT INTO Tache VALUES (NULL, :intitule, 0,:idListe)"; + + $co->executeQuery($query, array(':intitule' => array($nom, PDO::PARAM_STR), + 'idListe' => array($idListe,PDO::PARAM_INT))); + } + catch(PDOException $Exception){ + echo 'erreur'; + echo $Exception->getMessage(); } } public function delTache(int $id){ - if(!empty($id)){ - try{ - $co = $this->co; + try{ + $co = $this->co; - $query = "DELETE FROM Tache WHERE id=:id"; + $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(); - } + $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)){ + public function updateTache(int $id, bool $complete){ try{ $co = $this->co; - - $query = "UPDATE Tache SET isCompleted=true WHERE id=:id"; + if($complete==true){ + $query = "UPDATE Tache SET complete=0 WHERE id=:id"; + } + else{ + $query = "UPDATE Tache SET complete=1 WHERE id=:id"; + } + $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); } @@ -132,6 +162,23 @@ class ListeGateway { echo 'erreur'; echo $Exception->getMessage(); } + } + + public function getTacheById(int $id){ + $complete=null; + $co=$this->co; + $query="SELECT complete FROM Tache WHERE id=:id"; + $co->executeQuery($query,array('id'=>array($id,PDO::PARAM_INT))); + $res=$co->getResults(); + foreach($res as $row){ + $complete=$row['complete']; + } + if($complete=="0") + { + return false; + } + else{ + return true; } } @@ -153,18 +200,16 @@ class ListeGateway { 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(); - } + try{ + $co = $this->co; + $queryDelTaches="DELETE FROM Tache WHERE idListe=:id"; + $query = "DELETE FROM Liste WHERE id=:id"; + $co->executeQuery($queryDelTaches, array(':id' => array($id, PDO::PARAM_STR))); + $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); + } + catch(PDOException $Exception){ + echo 'erreur'; + echo $Exception->getMessage(); } } } diff --git a/modeles/Modele/ListModel.php b/modeles/Modele/ListModel.php index 0f0017b..ca5acfe 100644 --- a/modeles/Modele/ListModel.php +++ b/modeles/Modele/ListModel.php @@ -11,7 +11,7 @@ class ListeModel{ function creerListe(string $nom, $private){ if(isset($_SESSION['login'])){ - if($private="on"){ + if($private!=null){ $this->listgw->creerListe($nom,$_SESSION['login']); }else{ $this->listgw->creerListe($nom,null); @@ -20,6 +20,27 @@ class ListeModel{ $this->listgw->creerListe($nom,null); } } + + function pullListById(int $idListe){ + return $this->listgw->getById($idListe); + } + + function addTache(string $intitule, int $idListe ){ + $this->listgw->creerTache($intitule,$idListe); + } + + function delTache(int $idTache){ + $this->listgw->delTache($idTache); + } + + function changeCompletedTache(int $idTache){ + $complete=$this->listgw->getTacheById($idTache); + $this->listgw->updateTache($idTache,$complete); + } + + function delListe(int $idListe){ + $this->listgw->delListe($idListe); + } } ?> \ No newline at end of file diff --git a/vues/acceuil.php b/vues/acceuil.php index 1b829ca..bdb4909 100644 --- a/vues/acceuil.php +++ b/vues/acceuil.php @@ -43,14 +43,15 @@ nom; - echo '
'; - if($liste->taches != null){ - foreach($liste->taches as $tache){ - echo ' * '.$tache->nom; - echo '
'; - } - } + echo ' +
+
+

• '.$liste->nom.' +

+ + +
+
'; } } ?> diff --git a/vues/connection.php b/vues/connection.php index 86bc3ba..cf29570 100644 --- a/vues/connection.php +++ b/vues/connection.php @@ -7,6 +7,10 @@

You are back ?!

+
+ + +
diff --git a/vues/creationListe.php b/vues/creationListe.php index b222d8b..2e16d0e 100644 --- a/vues/creationListe.php +++ b/vues/creationListe.php @@ -4,11 +4,11 @@

Create a new list

-

Name of the liste +

Name of the list

+ echo ' '; } ?> diff --git a/vues/creationTache.php b/vues/creationTache.php new file mode 100644 index 0000000..b4161e4 --- /dev/null +++ b/vues/creationTache.php @@ -0,0 +1,15 @@ + + + +
+

Create a new list

+ +

Name of the task +

+ + + + +
+ + \ No newline at end of file diff --git a/vues/infosListe.php b/vues/infosListe.php new file mode 100644 index 0000000..eb6c424 --- /dev/null +++ b/vues/infosListe.php @@ -0,0 +1,64 @@ + + +
+

nom?>

+
+ + +
+
+ +
+ taches != null){ + foreach($dataView->taches as $tache){ + if($tache->isCompleted == true){ + echo ' + + +
+ + + + +
+ '; + } + else{ + echo ' + + +
+ + + + +
+ '; + } + echo ' +
+ + + + +
'; + echo '
'; + } + } + } + ?> +
+

+ + +
+
+

+ + +
+
+ + \ No newline at end of file diff --git a/vues/listesPrivees.php b/vues/listesPrivees.php index 422d55e..aa57fb9 100644 --- a/vues/listesPrivees.php +++ b/vues/listesPrivees.php @@ -1,19 +1,27 @@ +
+

Private Lists

+
+ + +
+
-

Private Lists

+ nom; - echo '
'; - if($liste->taches != null){ - foreach($liste->taches as $tache){ - echo ' * '.$tache->nom; - echo '
'; - } - } + echo ' +
+
+

• '.$liste->nom.' +

+ + +
+
'; } } ?> diff --git a/vues/profile.php b/vues/profile.php index c538361..742613c 100644 --- a/vues/profile.php +++ b/vues/profile.php @@ -1,19 +1,19 @@ +
+

What you wanna do young padawan?

+
+ + +
+
-

What you wanna young padawan?

-
-
- - -
-
\ No newline at end of file