From 1f52b959341191da16c19e9466d2a743d84514c9 Mon Sep 17 00:00:00 2001 From: "nicolas.franco" Date: Sun, 11 Dec 2022 17:43:34 +0100 Subject: [PATCH] gtw list funcitons added + model functions --- business/ListTask.php | 4 +++- dal/TaskGateway.php | 33 +++++++++++++++++++++++---------- model/TaskModel.php | 26 ++++++++++++++++++++++---- tests/test.php | 8 ++++---- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/business/ListTask.php b/business/ListTask.php index b43e6ae..aa34586 100644 --- a/business/ListTask.php +++ b/business/ListTask.php @@ -6,7 +6,7 @@ private string $owner; private int $dc; // done counter - function __construct($id, $nom, $owner="") { + function __construct($id, $nom, $owner="", $dc=0) { $this->id = $id; $this->nom = $nom; $this->taches = []; @@ -38,6 +38,8 @@ } function get_owner() { + if($this->owner == "") + return NULL; return $this->owner; } diff --git a/dal/TaskGateway.php b/dal/TaskGateway.php index b11951c..a5e0b72 100644 --- a/dal/TaskGateway.php +++ b/dal/TaskGateway.php @@ -14,7 +14,7 @@ class TaskGateway // functions // code de retour pour les fonctions i,u,d? - public function insert(Task $t){ + public function insertT(Task $t){ $query='INSERT INTO Tache VALUES (:id,:titre,:descript,NULL,NULL,:priorite,:idList,false)'; $this->con->executeQuery($query, array( @@ -29,20 +29,23 @@ class TaskGateway */ } - public function update($id,$element, $valeur){ - $query='UPDATE Tache SET '.$element.'=:'.$element.' WHERE id=:id'; - + public function update($table,$id,$element, $valeur){ + if($table == 'task'){ + $query='UPDATE Tache SET '.$element.'=:'.$element.' WHERE id=:id'; + } else { + $query='UPDATE uList SET '.$element.'=:'.$element.' WHERE id=:id'; + } $this->con->executeQuery($query, array( ':id'=>array($id,PDO::PARAM_STR), ':'.$element =>array($valeur,PDO::PARAM_STR))); - /* - element é o attributo da classe, valaeur é oque queremos botar - */ } - public function delete($id){ - $query='DELETE FROM Tache WHERE id = :id'; - + public function delete($table,$id){ + if($table == 'task'){ + $query='DELETE FROM Tache WHERE id = :id'; + } else { + $query='DELETE FROM uList WHERE id = :id'; + } $this->con->executeQuery($query, array( ':id'=>array($id,PDO::PARAM_STR))); } @@ -69,5 +72,15 @@ class TaskGateway } return $tabTaches; } + + /* # LIST FUNCTIONS */ + /*create, update, delete, read(select info)*/ + public function insertL(ListTask $l){ + $query='INSERT INTO uList VALUES (:id,:nom,:user,0)'; + $this->con->executeQuery($query, array( + ':id'=> array($l->get_id(),PDO::PARAM_STR), + ':nom'=> array($l->get_nom(),PDO::PARAM_STR), + ':user'=> array($l->get_owner(),PDO::PARAM_STR))); + } } ?> diff --git a/model/TaskModel.php b/model/TaskModel.php index 91cc886..a505afa 100644 --- a/model/TaskModel.php +++ b/model/TaskModel.php @@ -16,18 +16,18 @@ class TaskModel public function addTask($id,$titre,$desc,$priorite,$idList,$dateDeb="",$dateFin="",$isDone=false) { $t = new Task($id,$titre,$desc,$priorite,$idList,$dateDeb,$dateFin,$isDone); - $this->gtw->insert($t); + $this->gtw->insertT($t); // retourne quoi? con->lastInsertId() ?? } - public function supTask($element,$valeur) + public function supTask($id) { - $this->gtw->delete($element,$valeur); + $this->gtw->delete('task',$id); } public function modifTask($id,$element,$valeur) { - $this->gtw->update($id,$element,$valeur); + $this->gtw->update('task',$id,$element,$valeur); } public function getAllTask() @@ -39,5 +39,23 @@ class TaskModel { return $this->gtw->find($element,$valeur); } + + /* LIST FUNCTIONS */ + public function addList($id,$nom,$owner="",$dc=0) + { + $l = new ListTask($id,$nom,$owner="",$dc=0); + $this->gtw->insertL($l); + // retourne quoi? con->lastInsertId() ?? + } + + public function modifList($id,$element,$valeur) + { + $this->gtw->update('list',$id,$element,$valeur); + } + + public function supList($id) + { + $this->gtw->delete('list',$id); + } } ?> diff --git a/tests/test.php b/tests/test.php index 05325b6..b2123f5 100644 --- a/tests/test.php +++ b/tests/test.php @@ -26,12 +26,12 @@ foreach($tasks as $i) # Test du modele Tache $mt= new TaskModel($con); //$mt->addTask('3','testIsDone','desc.','urgent','001'); -$mt->modifTask('3','isDone','1'); +//$mt->modifTask('3','isDone','1'); //$tasks = $mt->getTaskBy('titre','tache1'); $tasks = $mt->getAllTask(); foreach($tasks as $i) echo $i->get_id()."
"; -//$l1 = new ListTask('001','todo1' ,'nifranco'); -//$li->set_taches($mt->) - +$mt->addList('002','todo2','nifranco'); +$mt->modifList('2','nom','22do'); +//$mt->supList('2');