From c64bf617b93525a9177aafae10c8090a79c89520 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Thu, 3 Dec 2015 10:43:27 +0100 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mentation=20des=20Repo=20Patient=20et?= =?UTF-8?q?=20Medecin=20(pas=20test=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Docs/BDD.sql | 2 +- repositories/StaticRepo.php | 3 +++ repositories/repos/MedecinRepo.php | 24 ++++++++++++++++++++---- repositories/repos/PatientRepo.php | 23 +++++++++++++++++++---- src/Authentification.php | 4 ++-- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Docs/BDD.sql b/Docs/BDD.sql index ac9320d..966eaff 100644 --- a/Docs/BDD.sql +++ b/Docs/BDD.sql @@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS `Patient` ( `Adresse` varchar(255) NOT NULL, `Adresse 2` varchar(255) DEFAULT NULL, `Ville` varchar(50) NOT NULL, - `CodePostal` varchar(4) NOT NULL, + `CodePostal` varchar(5) NOT NULL, `DateNaissance` date NOT NULL, `LieuNaissance` varchar(50) NOT NULL, `NumSecuriteSociale` varchar(15) NOT NULL, diff --git a/repositories/StaticRepo.php b/repositories/StaticRepo.php index e42f1fe..2855736 100755 --- a/repositories/StaticRepo.php +++ b/repositories/StaticRepo.php @@ -43,6 +43,9 @@ class StaticRepo{ * */ public static function delNumeric($fetchData, $oneDimension=false){ + + // cas où fetch renvoie FALSE + if( $fetchData === false ) return false; /* [1] 2 dimensions ===============================================*/ diff --git a/repositories/repos/MedecinRepo.php b/repositories/repos/MedecinRepo.php index 4545fda..337753c 100644 --- a/repositories/repos/MedecinRepo.php +++ b/repositories/repos/MedecinRepo.php @@ -22,19 +22,35 @@ class MedecinRepo } public function add($civilite,$prenom,$nom){ - + $req = $this->connexion->prepare('INSERT INTO Medecin VALUES (DEFAULT,:civilite,:prenom,:nom)'); + $result = $req->execute(['civilite' => $civilite, + 'nom' => $nom, + 'prenom' => $prenom)); + if($result){return ['id' => $this->connexion->lastInsertId()];} + else{return false;} } - public function delete($idPatient){ - + public function delete($idMedecin){ + $req = $this->connexion->prepare('DELETE FROM Medecin WHERE Id = :id'); + return $req->execute(['id' => $idMedecin]); } public function search($nom,$prenom){ + $req = $this->connexion->prepare('SELECT * FROM Medecin WHERE Nom LIKE :nom AND Prenom LIKE :prenom'); + $req->execute(['nom' => $nom, + 'prenom' => $prenom]); + return StaticRepo::delNumeric($req->fetchAll()); } public function getPatients($idMedecin){ + $req = $this->connexion->prepare('SELECT Patient.* FROM Patient,Medecin + WHERE Medecin.Id = :id + AND Medecin.Id = Patient.MedecinTraitant'); + + $req->execute(['id' => $idMedecin]); + return StaticRepo::delNumeric($req->fetchAll()); } -} \ No newline at end of file +} diff --git a/repositories/repos/PatientRepo.php b/repositories/repos/PatientRepo.php index caa6dd4..71cb119 100644 --- a/repositories/repos/PatientRepo.php +++ b/repositories/repos/PatientRepo.php @@ -17,14 +17,14 @@ class PatientRepo public function getById($id){ $req = $this->connexion->prepare('SELECT * FROM Patient WHERE Id = :id'); $req->execute(['id' => $id]); - return $req->fetchAll(); + return StaticRepo::delNumeric( $req->fetch(), true ); } public function add($civilite,$prenom,$nom,$adresse,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){ $req = $this->connexion->prepare('INSERT INTO Patient VALUES (:civilite,:nom,:prenom,:adresse,:ville,:codePostal,:dateNaissance,:lieuNaissance,:numSecu,DEFAULT,:medecin)'); - $req->execute(['civilite' => $civilite, + $result = $req->execute(['civilite' => $civilite, 'nom' => $nom, 'prenom' => $prenom, 'adresse' => $adresse, @@ -34,19 +34,34 @@ class PatientRepo 'lieuNaissance' => $lieuNaissance, 'numSecu' => $numSecu, 'medecin' => $medecinTraitant ]); + if($result){return ['id' => $this->connexion->lastInsertId()];} + else{return false;} } public function delete($idPatient){ + $req = $this->connexion->prepare('DELETE FROM Patient WHERE Id = :id'); + return $req->execute(['id' => $idPatient]); + } - public function updateMedecinTraitant($idPatient,$IdMedecin){ + public function updateMedecinTraitant($idPatient,$idMedecin){ + + $req = $this->connexion->prepare('UPDATE Patient SET MedecinTraitant = :medecin WHERE Id = :id'); + return $req->execute['medecin' => $idMedecin, + 'id' => $idPatient]); } public function search($nom,$prenom){ + $req = $this->connexion->prepare('SELECT * FROM Patient WHERE Nom LIKE :nom AND Prenom LIKE :prenom'); + $req->execute(['nom' => $nom, + 'prenom' => $prenom]); + + return StaticRepo::delNumeric($req->fetchAll()); + } -} \ No newline at end of file +} diff --git a/src/Authentification.php b/src/Authentification.php index a81fd19..311c349 100755 --- a/src/Authentification.php +++ b/src/Authentification.php @@ -43,7 +43,7 @@ class Authentification{ $id = uniqid(); $_SESSION['id'] = $id; $_SESSION['token'] = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$id); - setcookie('UserId',$id,time()+10*60,'/'); + session_regenerate_id(); $_SESSION['user'] = $user; $_SESSION['role'] = $role; @@ -71,7 +71,7 @@ class Authentification{ foreach($_SESSION['role'] as $roleUser){ if(($strict and $roleUser == $role) or (!$strict and $roleUser<= $role)){ if($_SESSION['token'] == sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$_SESSION['id'])){ - setcookie('UserId',$_COOKIE['UserId'],time()+10*60,'/'); + session_regenerate_id(); return true; }; }