fonction loadPrivateLists, taskModel

userctrl
Nicolas FRANCO 2 years ago
parent e518f24104
commit ca4a84a4a6

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

@ -1,6 +1,6 @@
<?php
class User{
private string $login;
private string $login; // botar um id no final se der tempo
function __construct($login) {
$this->login = $login;

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

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

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

@ -7,7 +7,7 @@ echo "<h1>2do test</h1>";
# 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()."<br>";
// }
# test find
/*$tasks=$tgt->find('idList','001');
foreach($tasks as $i)
echo $i->get_id()."<br>"; */
# 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()."<br>";
$lists = $mt->loadPrivateLists('nifranco');
foreach($lists as $l){
echo 'List: '.$l->get_id()."<br>";
echo "Tasks: <br>";
foreach($l->get_taches() as $t){
echo $t->get_id()."<br>";
}
}
// $mt->addList('002','todo2','nifranco');
// $mt->modifList('2','nom','22do');

Loading…
Cancel
Save