Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
57.14% covered (warning)
57.14%
4 / 7
CRAP
85.11% covered (warning)
85.11%
40 / 47
RDVRepo
0.00% covered (danger)
0.00%
0 / 1
57.14% covered (warning)
57.14%
4 / 7
19.07
85.11% covered (warning)
85.11%
40 / 47
 getById
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 getByDate
0.00% covered (danger)
0.00%
0 / 1
4.05
20.00% covered (danger)
20.00%
1 / 5
 delete
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 add
0.00% covered (danger)
0.00%
0 / 1
6.02
91.67% covered (success)
91.67%
11 / 12
 updateDateTime
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 getByPatientAndDate
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 getAll
0.00% covered (danger)
0.00%
0 / 1
4.05
85.71% covered (warning)
85.71%
12 / 14
<?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 getByDate($date){
        if(!StaticRepo::checkParam($date,'Date')){return false;}
        $date = date('Y-m-d',strtotime($date));
        $req = StaticRepo::getConnexion()->prepare('SELECT * 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,'Integer')){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;}
        $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,$dateTime){
        $date = date('Y-m-d H:i:s',strtotime($dateTime));
        $req = StaticRepo::getConnexion()->prepare('UPDATE RDV SET DateRDV = :date WHERE id = :id');
        return $req->execute(['date' => $date,
            'id' => $idRDV]);
    }
    public static function getByPatientAndDate($idPatient,$date){
        $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){
        $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());
    }
}