Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
90.00% |
9 / 10 |
CRAP | |
97.40% |
75 / 77 |
RDVRepo | |
0.00% |
0 / 1 |
|
90.00% |
9 / 10 |
35 | |
97.40% |
75 / 77 |
getById | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
getForMonth | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
getByDate | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
delete | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
add | |
100.00% |
1 / 1 |
7 | |
100.00% |
13 / 13 |
|||
updateDateTime | |
100.00% |
1 / 1 |
3 | |
100.00% |
9 / 9 |
|||
getByPatientAndDate | |
100.00% |
1 / 1 |
3 | |
100.00% |
6 / 6 |
|||
getAll | |
0.00% |
0 / 1 |
5.06 | |
86.67% |
13 / 15 |
|||
getByMonth | |
100.00% |
1 / 1 |
2 | |
100.00% |
7 / 7 |
|||
isPossible | |
100.00% |
1 / 1 |
8 | |
100.00% |
11 / 11 |
<?php | |
/** | |
* Created by PhpStorm. | |
* User: seekdasky | |
* Date: 02/12/15 | |
* Time: 12:36 | |
*/ | |
class RDVRepo | |
{ | |
public static function getById($id){ | |
if(!StaticRepo::checkParam($id,'Integer')){return false;} | |
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV WHERE RDV.id = :id'); | |
$req->execute(['id' => $id]); | |
return StaticRepo::delNumeric( $req->fetch(), true ); | |
} | |
public static function getForMonth($month, $year){ | |
$req = StaticRepo::getConnexion()->prepare("SELECT RDV.Id, RDV.DateRDV, RDV.Medecin_Id, RDV.Patient_Id, RDV.Duree, Medecin.Prenom as M_Prenom, Medecin.Nom as M_Nom, Patient.Prenom as P_Prenom, Patient.Nom as P_Nom | |
FROM RDV, Patient, Medecin | |
WHERE Patient.Id = RDV.Patient_Id | |
AND Medecin.Id = RDV.Medecin_Id | |
AND MONTH(DateRDV) = :month | |
AND YEAR(DateRDV) = :year | |
ORDER BY DateRDV ASC"); | |
$req->execute(array( ':month' => $month, ':year' => $year )); | |
return $req->fetchAll(); | |
} | |
public static function getByDate($date){ | |
if(!StaticRepo::checkParam($date,'Date')){return false;} | |
$date = date('Y-m-d',strtotime($date)); | |
$req = StaticRepo::getConnexion()->prepare('SELECT * , ((HOUR(Duree)*60)+MINUTE(Duree)) AS Minute FROM RDV WHERE DATE(DateRDV) = :date ORDER BY DateRDV ASC'); | |
$req->execute(['date' => $date]); | |
return StaticRepo::delNumeric($req->fetchAll()); | |
} | |
public static function delete($idRDV){ | |
if(!StaticRepo::checkParam($idRDV,'Numeric')){return false;} | |
$req = StaticRepo::getConnexion()->prepare('DELETE FROM RDV WHERE RDV.id = :id'); | |
return $req->execute(['id' => $idRDV]); | |
} | |
public static function add($date,$duree,$idPatient,$idMedecin){ | |
if(!StaticRepo::checkParam($date,'Date') && !StaticRepo::checkParam($duree,'Integer') && !StaticRepo::checkParam($idPatient,'Integer') && !StaticRepo::checkParam($idMedecin,'Integer')){return false;} | |
if(!static::isPossible($date,$duree,$idMedecin)){return false;} | |
$date = date('Y-m-d H:i:s',strtotime($date)); | |
$duree = date('H:i:s',$duree*60); | |
$req = StaticRepo::getConnexion()->prepare('INSERT INTO RDV VALUES (DEFAULT,:date,:duree,:patient,:medecin)'); | |
$result = $req->execute(['date' => $date, | |
'duree' => $duree, | |
'patient' => $idPatient, | |
'medecin' => $idMedecin]); | |
//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 updateDateTime($idRDV, $dateRdv, $duree){ | |
if(!StaticRepo::checkParam($idRDV, 'Numeric')) return false; | |
$rdv = static::getById($idRDV); | |
$dateRdv = date('Y-m-d H:i:s',strtotime($dateRdv)); | |
if(!static::isPossible($dateRdv,((date('H',strtotime($duree))*60)+date('i',strtotime($duree))),$rdv['Medecin_id'],$idRDV)){return false;} | |
$req = StaticRepo::getConnexion()->prepare('UPDATE RDV SET DateRDV = :date_rdv, Duree = :duree WHERE id = :id'); | |
return $req->execute([ | |
':date_rdv' => $dateRdv, | |
':duree' => $duree, | |
':id' => $idRDV | |
]); | |
} | |
public static function getByPatientAndDate($idPatient,$date){ | |
if(!StaticRepo::checkParam($idPatient,'Integer') && !StaticRepo::checkParam($date,'Date')){return false;} | |
$date = date('Y-m-d',strtotime($date)); | |
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV WHERE Patient_Id=:patient AND DATE(DateRDV)=:date'); | |
$req->execute(['patient' => $idPatient, | |
'date' => $date]); | |
return StaticRepo::delNumeric($req->fetchAll()); | |
} | |
public static function getAll($date = 0){ | |
if(!StaticRepo::checkParam($date,'Integer')){return false;} | |
$dateTime = date('Y-m-d',time()); | |
switch($date){ | |
case -1: | |
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV WHERE DATE(DateRDV) <= :date ORDER BY DateRDV ASC'); | |
$req->execute(['date' => $dateTime]); | |
break; | |
case 0: | |
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV ORDER BY DateRDV ASC'); | |
$req->execute(); | |
break; | |
case 1: | |
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV WHERE DATE(DateRDV) >= :date ORDER BY DateRDV ASC'); | |
$req->execute(['date' => $dateTime]); | |
break; | |
} | |
return StaticRepo::delNumeric($req->fetchAll()); | |
} | |
public static function getByMonth($date){ | |
$strDate = date( 'Y-m-d', $date ); | |
// si erreur on retourne un tableau vide | |
if( !StaticRepo::checkParam($strDate, 'Date') ) return []; | |
$req = StaticRepo::getConnexion()->prepare('SELECT *, ((HOUR(Duree)*60)+MINUTE(Duree)) AS Minute FROM RDV WHERE MONTH(DateRDV) = :month AND YEAR(DateRDV) = :year ORDER BY DateRDV ASC'); | |
$req->execute([ | |
'month' => date( 'm', $date ), | |
'year' => date( 'Y', $date ) | |
]); | |
return StaticRepo::delNumeric( $req->fetchAll() ); | |
} | |
public static function isPossible($date,$duree,$medecin,$ignore = -1){ | |
$dateRequest = date('Y-m-d',strtotime($date)); | |
//$duree = date('H:i:s',$duree*60); | |
$rdvs = static::getByDate($dateRequest); | |
foreach($rdvs as $rdv){ | |
if($rdv['Medecin_id'] == $medecin and $rdv['Id'] != $ignore){ | |
$minDate = strtotime($rdv['DateRDV']); | |
$maxDate = $minDate + $rdv['Minute']*60; | |
$actualMinDate = strtotime($date); | |
$actualMaxDate = $actualMinDate+($duree*60); | |
if( ($minDate <= $actualMinDate) && ($actualMinDate <= $maxDate) || ($minDate <= $actualMaxDate) && ($actualMaxDate <= $maxDate)){ | |
return false; | |
} | |
} | |
} | |
return true; | |
} | |
} |