From a5b6c86abb6438ffbdb3058eaf4f45ff91b582bc Mon Sep 17 00:00:00 2001 From: thchazot1 Date: Fri, 23 Dec 2022 16:54:58 +0100 Subject: [PATCH] wouhou --- config/config.php | 6 +++--- gateway/UserGateway.php | 8 ++++++-- modeles/MdlListe.php | 8 +++----- modeles/MdlUser.php | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/config/config.php b/config/config.php index 7c01a02..c9563fc 100644 --- a/config/config.php +++ b/config/config.php @@ -2,9 +2,9 @@ $rep = __DIR__ . '/../'; -$login="root"; -$password="root"; -$dsn="mysql:host=localhost;port=8888;dbname=bddDeQualite"; // chemin vers bd (mysql:host=londres.uca.local;dbname=dblibreton => pour l'iut) +$login="thchazot1"; +$password="achanger"; +$dsn="mysql:host=localhost;dbname=dbthchazot1"; // chemin vers bd (mysql:host=londres.uca.local;dbname=dblibreton => pour l'iut) //$dsn="mysql:host=localhost;port=8888;dbname=bddDeQualite"; /* $login="thchazot1"; diff --git a/gateway/UserGateway.php b/gateway/UserGateway.php index 4624648..dd92bd1 100644 --- a/gateway/UserGateway.php +++ b/gateway/UserGateway.php @@ -34,11 +34,15 @@ class UserGateway $this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT), ':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR))); } - public function findByName(string $username): array{ + public function findByName(string $username): ?User{ + $usr=null; $query = "SELECT * FROM Utilisateur WHERE username=:username"; $this->con->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR))); $results=$this->con->getResults(); - return $results[0]; + foreach ($results as $user){ + $usr = new User($user['id'], $user['username'], $user['password']); + } + return $usr; } public function getLastId(): array{ diff --git a/modeles/MdlListe.php b/modeles/MdlListe.php index 716c64b..c42ec34 100644 --- a/modeles/MdlListe.php +++ b/modeles/MdlListe.php @@ -71,14 +71,12 @@ class MdlListe{ return $tabListe; } - public function findByUser(string $username): array{ + public function findByUser(User $user): array{ $gate=new ListeGateway($this->con); $gateTache=new TacheGateway($this->con); $gateUser=new UserGateway($this->con); - $id=$gateUser->findByName($username); - $id=$id['id']; - $results=$gate->findByUserId($id); + $results=$gate->findByUserId($user->getId()); $tabListe=[]; foreach ($results as $row ) { $tabTache=[]; @@ -86,7 +84,7 @@ class MdlListe{ foreach($taches as $tata){ $tabTache[]=new Tache($tata['id'], $tata['name'], $tata['content'], $tata['completed']); } - $tabListe[]=new Liste($row['id'], $row['name'], $row['private'], $u, $tabTache); + $tabListe[]=new Liste($row['id'], $row['name'], $row['private'], $user, $tabTache); } return $tabListe; } diff --git a/modeles/MdlUser.php b/modeles/MdlUser.php index a1a77d8..f27af96 100644 --- a/modeles/MdlUser.php +++ b/modeles/MdlUser.php @@ -60,7 +60,7 @@ class MdlUser{ public function findByName(string $usr){ $gate=new UserGateway($this->con); $result=$gate->findByName($usr); - return new User($result['id'], $usr, $result['password']); + return $result; } }