fonction loadPrivateLists, taskModel

userctrl
Nicolas FRANCO 2 years ago
parent e518f24104
commit ca4a84a4a6

@ -4,7 +4,7 @@
private string $nom; private string $nom;
private array $taches; private array $taches;
private $owner; private $owner;
private int $dc; // done counter private int $dc; // done counter # juste visuelle??
function __construct($id, $nom, $owner="", $dc=0) { function __construct($id, $nom, $owner="", $dc=0) {
$this->id = $id; $this->id = $id;

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

@ -3,8 +3,8 @@ require_once('../model/UserModel.php');
class FrontController class FrontController
{ {
private UserModel $ursMdl; //private UserModel $ursMdl;
private $action_User; //private $action_User;
function __construct($ursMdl=new UserModel(), $action_User=[]){ function __construct($ursMdl=new UserModel(), $action_User=[]){
$this->$ursMdl = $ursMdl; $this->$ursMdl = $ursMdl;
@ -21,10 +21,11 @@ class FrontController
require("VisitCtrl.php"); require("VisitCtrl.php");
$visitCtrl = new VisitCtrl(); $visitCtrl = new VisitCtrl();
$visitCtrl.handleAction('connecter'); $visitCtrl.handleAction('connecter');
// inclure la vue de connexion
} else { # sinon } else { # sinon
# handle action avec controlleur user # handle action avec controlleur user
require("UserCtrl.php"); require("UserCtrl.php");
$userCtrl = new UserCtrl(); $userCtrl = new UserCtrl(); //action ici
$userCtrl.handleAction($action); $userCtrl.handleAction($action);
} }

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

Loading…
Cancel
Save