From ca4a84a4a618919053349460518971411f1a7ba9 Mon Sep 17 00:00:00 2001 From: "nicolas.franco" Date: Wed, 21 Dec 2022 16:32:02 +0100 Subject: [PATCH] fonction loadPrivateLists, taskModel --- business/ListTask.php | 2 +- business/User.php | 2 +- controller/FrontCtrl.php | 7 ++++--- dal/TaskGateway.php | 35 +++++++++++++++++++++++++++++++++++ model/TaskModel.php | 14 +++++++++++++- tests/test.php | 25 ++++++++++++++++--------- 6 files changed, 70 insertions(+), 15 deletions(-) diff --git a/business/ListTask.php b/business/ListTask.php index 5d0c002..9710ce1 100644 --- a/business/ListTask.php +++ b/business/ListTask.php @@ -4,7 +4,7 @@ private string $nom; private array $taches; private $owner; - private int $dc; // done counter + private int $dc; // done counter # juste visuelle?? function __construct($id, $nom, $owner="", $dc=0) { $this->id = $id; diff --git a/business/User.php b/business/User.php index 7de66c5..3c3c203 100644 --- a/business/User.php +++ b/business/User.php @@ -1,6 +1,6 @@ login = $login; diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index 1f9c58a..a2a11b5 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -3,8 +3,8 @@ require_once('../model/UserModel.php'); class FrontController { - private UserModel $ursMdl; - private $action_User; + //private UserModel $ursMdl; + //private $action_User; function __construct($ursMdl=new UserModel(), $action_User=[]){ $this->$ursMdl = $ursMdl; @@ -21,10 +21,11 @@ class FrontController require("VisitCtrl.php"); $visitCtrl = new VisitCtrl(); $visitCtrl.handleAction('connecter'); + // inclure la vue de connexion } else { # sinon # handle action avec controlleur user require("UserCtrl.php"); - $userCtrl = new UserCtrl(); + $userCtrl = new UserCtrl(); //action ici $userCtrl.handleAction($action); } diff --git a/dal/TaskGateway.php b/dal/TaskGateway.php index 8bff2ee..f63b3bc 100644 --- a/dal/TaskGateway.php +++ b/dal/TaskGateway.php @@ -107,5 +107,40 @@ class TaskGateway ':nom'=> array($l->get_nom(),PDO::PARAM_STR), ':user'=> array($l->get_owner(),PDO::PARAM_STR))); } + + public function findUserList($user){ + # pas réussit a faire une jointure optimale donc + # decomposé en plusieurs foncitons: + # findUserList + # findTacheList + + $query='SELECT * from uList where user = :user'; + $this->con->executeQuery($query, array( + ':user' => array($user,PDO::PARAM_STR) + )); + + $results = $this->con->getResults(); + foreach($results as $row){ + $tabLists[]= new ListTask($row[0],$row[1],$row[2],$row[3]); + } + return $tabLists; + } + + public function findListTask($list){ + $query='SELECT * from Tache where idList = :idList'; + + $this->con->executeQuery($query, array( + ':idList' => array($list->get_id(),PDO::PARAM_STR) + )); + + $results = $this->con->getResults(); + + foreach($results as $row){ + $taches[]= new Task($row['id'],$row['titre'],$row['description'],$row['priorite'], + $row['idList'],$row['dateDebut'],$row['dateFin'],$row['isDone']); + } + $list->set_taches($taches); + return $list; + } } ?> diff --git a/model/TaskModel.php b/model/TaskModel.php index 7554801..99d53af 100644 --- a/model/TaskModel.php +++ b/model/TaskModel.php @@ -60,7 +60,19 @@ class TaskModel function loadPublicLists() { - return $this->gtw->find('list','user','NULL'); + return $this->gtw->find('list','user','NULL'); // is null!! + // requete avec jointure pour optimizer requete + } + + function loadPrivateLists($user){ + # prend toutes les listes de l'user + $lists = $this->gtw->findUserList($user); + + # pour chacune de ses listes, charge les taches + foreach($lists as &$row){ + $row = $this->gtw->findListTask($row); + } + return $lists; } } ?> diff --git a/tests/test.php b/tests/test.php index 966084e..2ed5480 100644 --- a/tests/test.php +++ b/tests/test.php @@ -7,7 +7,7 @@ echo "

2do test

"; # Test de la Gateway Tache # nouvelle tache -$t = new Task(5,'tacheNotErr','desc.','urgent','001'); +# $t = new Task(5,'tacheNotErr','desc.','urgent','001'); # connection include("credentials.php"); @@ -17,20 +17,27 @@ $con = new Connection('mysql:host=localhost;dbname=phpproject',$user,$pass); $tgt = new TaskGateway($con); //$tgt->insert($t); //$tgt->delete('10'); +//$taches = $tgt->findUserList('nifranco'); +// foreach($taches as $t){ +// echo $t->get_id()." ".$t->get_idList()."
"; +// } # test find /*$tasks=$tgt->find('idList','001'); foreach($tasks as $i) echo $i->get_id()."
"; */ -# Test du modele Tache +# Test LOAD PRIVATE TASKS $mt= new TaskModel($con); -//$mt->addTask('3','testIsDone','desc.','urgent','001'); -//$mt->modifTask('3','isDone','1'); -//$tasks = $mt->getTaskBy('titre','tache1'); -$tasks = $mt->loadPublicLists(); -foreach($tasks as $i) - echo $i->get_id()."
"; +$lists = $mt->loadPrivateLists('nifranco'); + +foreach($lists as $l){ + echo 'List: '.$l->get_id()."
"; + echo "Tasks:
"; + foreach($l->get_taches() as $t){ + echo $t->get_id()."
"; + } +} // $mt->addList('002','todo2','nifranco'); // $mt->modifList('2','nom','22do'); @@ -58,7 +65,7 @@ require('../model/UserModel.php'); // $mdl->ajouter('Anna', 'unmdptrescomplique'); // $mdl->modifLogin('Anna', 'Aeryn'); // $mdl->modifMdp('Aeryn', 'wtfmec'); -// $mdl->supprimer('Aeryn'); +// $mdl->supprimer('Aeryn'); ?>