Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
85.71% |
6 / 7 |
CRAP | |
97.06% |
33 / 34 |
MedecinRepo | |
0.00% |
0 / 1 |
|
85.71% |
6 / 7 |
17 | |
97.06% |
33 / 34 |
getById | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
add | |
0.00% |
0 / 1 |
3.01 | |
88.89% |
8 / 9 |
|||
delete | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
search | |
100.00% |
1 / 1 |
6 | |
100.00% |
8 / 8 |
|||
getPatients | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
getAll | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
update | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
<?php | |
/** | |
* Created by PhpStorm. | |
* User: seekdasky | |
* Date: 02/12/15 | |
* Time: 12:36 | |
*/ | |
class MedecinRepo | |
{ | |
public static function getById($id){ | |
if(!StaticRepo::checkParam($id, 'Numeric')) return false; | |
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM Medecin WHERE Id = :id'); | |
$req->execute(['id' => $id]); | |
return StaticRepo::delNumeric( $req->fetch(), true ); | |
} | |
public static function add($civilite,$prenom,$nom){ | |
if(!StaticRepo::checkParam($civilite,'Civilite') | !StaticRepo::checkParam($prenom,'String45') | !StaticRepo::checkParam($nom,'String45')) return false; | |
$req = StaticRepo::getConnexion()->prepare('INSERT INTO Medecin VALUES (DEFAULT,:civilite,:prenom,:nom)'); | |
$result = $req->execute(['civilite' => $civilite, | |
'nom' => $nom, | |
'prenom' => $prenom | |
]); | |
//PDO renvoie un ID sous forme de char, on transtype | |
$id = StaticRepo::getConnexion()->lastInsertId(); | |
settype($id, 'integer'); | |
if($result) return $id; | |
else return false; | |
} | |
public static function delete($idMedecin){ | |
if(!StaticRepo::checkParam($idMedecin,'Numeric')) return false; | |
var_dump($idMedecin); | |
$req = StaticRepo::getConnexion()->prepare('DELETE FROM Medecin WHERE Id = :id'); | |
return $req->execute(['id' => $idMedecin]); | |
} | |
public static function search($nom, $prenom){ | |
if( !StaticRepo::checkParam($prenom,'String45') | !StaticRepo::checkParam($nom,'String45') ) return false; | |
// on définit les valeurs (peuvent être nulles) | |
$optPrenom = ( $prenom != 'null' && StaticRepo::checkParam($prenom,'String45') ) ? '%'.$prenom.'%' : '%'; | |
$optNom = ( $nom != 'null' && StaticRepo::checkParam($nom, 'String45') ) ? '%'.$nom.'%' : '%'; | |
$req = StaticRepo::getConnexion()->query("SELECT Id, Civilite, Prenom, Nom | |
FROM Medecin | |
WHERE Nom LIKE '".$optNom."' | |
AND Prenom LIKE '".$optPrenom."' | |
ORDER BY Nom, Prenom ASC"); | |
return StaticRepo::delNumeric( $req->fetchAll() ); | |
} | |
public static function getPatients($idMedecin){ | |
if(!StaticRepo::checkParam($idMedecin,'Numeric')) return false; | |
$req = StaticRepo::getConnexion()->prepare('SELECT Patient.* FROM Patient,Medecin | |
WHERE Medecin.Id = :id | |
AND Medecin.Id = Patient.MedecinTraitant'); | |
$req->execute(['id' => $idMedecin]); | |
return StaticRepo::delNumeric($req->fetchAll()); | |
} | |
public static function getAll(){ | |
$req = StaticRepo::getConnexion()->query('SELECT * FROM Medecin ORDER BY nom, prenom ASC'); | |
return StaticRepo::delNumeric( $req->fetchAll() ); | |
} | |
public static function update($id, $nom, $prenom){ | |
$req = StaticRepo::getConnexion()->prepare("UPDATE Medecin SET Nom = :nom, Prenom = :prenom WHERE Id = :id"); | |
return $req->execute([ ':nom' => strtoupper($nom), ':prenom' => $prenom, ':id' => $id ]); | |
} | |
} |