2015-12-02 12:31:37 +00:00
< ? php
/**
* Created by PhpStorm .
* User : seekdasky
* Date : 02 / 12 / 15
* Time : 12 : 36
*/
class RDVRepo
{
2015-12-08 08:31:47 +00:00
public static function getById ( $id ){
2015-12-10 10:46:29 +00:00
if ( ! StaticRepo :: checkParam ( $id , 'Integer' )){ return false ;}
2015-12-09 12:36:30 +00:00
$req = StaticRepo :: getConnexion () -> prepare ( 'SELECT * FROM RDV WHERE RDV.id = :id' );
2015-12-02 12:31:37 +00:00
$req -> execute ([ 'id' => $id ]);
2015-12-08 08:31:47 +00:00
return StaticRepo :: delNumeric ( $req -> fetch (), true );
2015-12-02 12:31:37 +00:00
}
2015-12-08 08:31:47 +00:00
public static function getByDate ( $date ){
2015-12-10 10:46:29 +00:00
if ( ! StaticRepo :: checkParam ( $date , 'Date' )){ return false ;}
2015-12-09 12:36:30 +00:00
$date = date ( 'Y-m-d' , strtotime ( $date ));
$req = StaticRepo :: getConnexion () -> prepare ( 'SELECT * FROM RDV WHERE DATE(DateRDV) = :date ORDER BY DateRDV ASC' );
2015-12-03 10:50:53 +00:00
$req -> execute ([ 'date' => $date ]);
return StaticRepo :: delNumeric ( $req -> fetchAll ());
2015-12-02 12:31:37 +00:00
}
2015-12-08 08:31:47 +00:00
public static function delete ( $idRDV ){
2015-12-10 10:46:29 +00:00
if ( ! StaticRepo :: checkParam ( $idRDV , 'Integer' )){ return false ;}
2015-12-09 12:36:30 +00:00
$req = StaticRepo :: getConnexion () -> prepare ( 'DELETE FROM RDV WHERE RDV.id = :id' );
2015-12-08 08:31:47 +00:00
return $req -> execute ([ 'id' => $idRDV ]);
2015-12-02 12:31:37 +00:00
}
2015-12-08 08:31:47 +00:00
public static function add ( $date , $duree , $idPatient , $idMedecin ){
2015-12-10 10:46:29 +00:00
if ( ! StaticRepo :: checkParam ( $date , 'Date' ) && ! StaticRepo :: checkParam ( $duree , 'Integer' ) && ! StaticRepo :: checkParam ( $idPatient , 'Integer' ) && ! StaticRepo :: checkParam ( $idMedecin , 'Integer' )){ return false ;}
2015-12-08 08:31:47 +00:00
$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 ]);
2015-12-10 10:46:29 +00:00
//PDO renvoie un ID sous forme de char, on transtype
$id = StaticRepo :: getConnexion () -> lastInsertId ();
settype ( $id , 'integer' );
if ( $result ){ return $id ;}
2015-12-08 08:31:47 +00:00
else { return false ;}
2015-12-02 12:31:37 +00:00
}
2015-12-08 08:31:47 +00:00
public static function updateDateTime ( $idRDV , $dateTime ){
2015-12-10 10:52:08 +00:00
if ( ! StaticRepo :: checkParam ( $idRDV , 'Integer' )){ return false ;}
2015-12-09 12:36:30 +00:00
$date = date ( 'Y-m-d H:i:s' , strtotime ( $dateTime ));
2015-12-08 08:31:47 +00:00
$req = StaticRepo :: getConnexion () -> prepare ( 'UPDATE RDV SET DateRDV = :date WHERE id = :id' );
return $req -> execute ([ 'date' => $date ,
'id' => $idRDV ]);
2015-12-02 12:31:37 +00:00
}
2015-12-08 08:31:47 +00:00
public static function getByPatientAndDate ( $idPatient , $date ){
2015-12-10 10:52:08 +00:00
if ( ! StaticRepo :: checkParam ( $idPatient , 'Integer' ) && ! StaticRepo :: checkParam ( $date , 'Date' )){ return false ;}
2015-12-09 12:36:30 +00:00
$date = date ( 'Y-m-d' , strtotime ( $date ));
$req = StaticRepo :: getConnexion () -> prepare ( 'SELECT * FROM RDV WHERE Patient_Id=:patient AND DATE(DateRDV)=:date' );
2015-12-08 08:31:47 +00:00
$req -> execute ([ 'patient' => $idPatient ,
'date' => $date ]);
return StaticRepo :: delNumeric ( $req -> fetchAll ());
2015-12-02 12:31:37 +00:00
}
2015-12-09 12:36:30 +00:00
public static function getAll ( $date = 0 ){
2015-12-10 10:52:08 +00:00
if ( ! StaticRepo :: checkParam ( $date , 'Integer' )){ return false ;}
2015-12-09 12:36:30 +00:00
$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 ());
}
2015-12-17 07:56:42 +00:00
public static function getByMonth ( $date ){
if ( ! StaticRepo :: checkParam ( $date , 'Date' )){ return false ;}
$date = date ( 'Y-m-d' , strtotime ( $date ));
2015-12-26 12:22:06 +00:00
$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' , strtotime ( $date )),
'year' => date ( 'Y' , strtotime ( $date ))]);
2015-12-17 07:56:42 +00:00
return StaticRepo :: delNumeric ( $req -> fetchAll ());
}
2015-12-03 10:02:05 +00:00
}