gtw list funcitons added + model functions

list-Gtw-Mdl
Nicolas FRANCO 2 years ago
parent 21de950b9f
commit 1f52b95934

@ -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;
}

@ -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)));
}
}
?>

@ -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);
}
}
?>

@ -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()."<br>";
//$l1 = new ListTask('001','todo1' ,'nifranco');
//$li->set_taches($mt->)
$mt->addList('002','todo2','nifranco');
$mt->modifList('2','nom','22do');
//$mt->supList('2');

Loading…
Cancel
Save