From d649927994ab94ad6159607a3a157e0b426f51a6 Mon Sep 17 00:00:00 2001 From: Lucas Mascaro Date: Sun, 3 Jan 2016 20:25:25 +0100 Subject: [PATCH] ajout du non-chevauchement --- coverage/StaticRepo.php.html | 34 ++-- coverage/dashboard.html | 12 +- coverage/index.html | 34 ++-- coverage/repos/MedecinRepo.php.html | 112 ++++++----- coverage/repos/PatientRepo.php.html | 2 +- coverage/repos/RDVRepo.php.html | 285 +++++++++++++++++----------- coverage/repos/StatsRepo.php.html | 2 +- coverage/repos/dashboard.html | 12 +- coverage/repos/index.html | 44 ++--- repositories/repos/MedecinRepo.php | 2 - repositories/repos/RDVRepo.php | 34 +++- test.php | 2 +- test/RDVRepoTest.php | 1 + 13 files changed, 329 insertions(+), 247 deletions(-) diff --git a/coverage/StaticRepo.php.html b/coverage/StaticRepo.php.html index 46cb735..f8b04e0 100755 --- a/coverage/StaticRepo.php.html +++ b/coverage/StaticRepo.php.html @@ -230,21 +230,21 @@
41
    public static function delNumeric($fetchData, $oneDimension=false){
42
    
43
    // cas où fetch renvoie FALSE -
44
    if( $fetchData === false ) return false; +
44
    if( $fetchData === false ) return false;
45
46
        /* [1] 2 dimensions
47
        ===============================================*/ -
48
        if( !$oneDimension ){ +
48
        if( !$oneDimension ){
49
50
        // on supprime les doublons des entrées (indice numérique) -
51
        for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs -
52
            foreach($fetchData[$i] as $col => $val){  // pour toutes les entrées +
51
        for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs +
52
            foreach($fetchData[$i] as $col => $val){  // pour toutes les entrées
53
                 -
54
                if( !mb_detect_encoding($val, 'UTF-8') ) +
54
                if( !mb_detect_encoding($val, 'UTF-8') )
55
                    $fetchData[$i][$col] = utf8_encode($val);
56
                 -
57
                if( is_int($col) )                    // si l'indice est un entier -
58
                    unset( $fetchData[$i][$col] );    // on le supprime +
57
                if( is_int($col) )                    // si l'indice est un entier +
58
                    unset( $fetchData[$i][$col] );    // on le supprime
59
            }
60
61
        /* [2] 1 dimensions @@ -252,18 +252,18 @@
63
        }else{
64
65
            // on supprime les doublons des entrées (indice numérique) -
66
            foreach($fetchData as $i=>$val){ // pour toutes les entrées +
66
            foreach($fetchData as $i=>$val){ // pour toutes les entrées
67
                 -
68
                if( !mb_detect_encoding($val, 'UTF-8') ) +
68
                if( !mb_detect_encoding($val, 'UTF-8') )
69
                    $fetchData[$i] = utf8_encode($val);
70
-
71
                if( is_int($i) )             // si l'indice est un entier -
72
                    unset( $fetchData[$i] ); // on le supprime +
71
                if( is_int($i) )             // si l'indice est un entier +
72
                    unset( $fetchData[$i] ); // on le supprime
73
            }
74
75
        }
76
-
77
        return $fetchData; +
77
        return $fetchData;
78
    }
79
80
@@ -318,8 +318,8 @@
129
                break;
130
131
            case 'Integer': -
132
                $checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 32); -
133
                break; +
132
                $checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 32); +
133
                break;
134
135
            case 'Numeric':
136
                $checker = $checker && !is_null($variable) && is_numeric($variable); @@ -338,8 +338,8 @@
149
                break;
150
151
            case 'Date': -
152
                $checker = $checker && !is_null($variable) && is_string($variable) && ( preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $variable) || preg_match('/^\d{4}-\d{2}-\d{2}$/', $variable) ); -
153
                break; +
152
                $checker = $checker && !is_null($variable) && is_string($variable) && ( preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $variable) || preg_match('/^\d{4}-\d{2}-\d{2}$/', $variable) ); +
153
                break;
154
155
            case 'Heure':
156
                $checker = $checker && !is_null($variable) && is_string($variable) && preg_match('/^\d{1,2}:\d{1,2}$/', $variable); @@ -372,7 +372,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 18:13:26 UTC 2016. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 19:23:14 UTC 2016.

diff --git a/coverage/dashboard.html b/coverage/dashboard.html index a737b65..a28f08e 100755 --- a/coverage/dashboard.html +++ b/coverage/dashboard.html @@ -115,7 +115,7 @@ checkParam80% delNumeric85% - getAll86% + getAll86% add88% @@ -135,7 +135,7 @@ checkParam51 delNumeric10 - getAll5 + getAll5 add3 @@ -146,7 +146,7 @@ @@ -185,7 +185,7 @@ $(document).ready(function() { .yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,4,3,22], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,4,3,23], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -235,7 +235,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[83.928571428571,54,"StaticRepo<\/a>"],[97.058823529412,17,"MedecinRepo<\/a>"],[97.590361445783,48,"PatientRepo<\/a>"],[96.774193548387,25,"RDVRepo<\/a>"],[93.548387096774,9,"StatsRepo<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[83.928571428571,54,"StaticRepo<\/a>"],[96.969696969697,17,"MedecinRepo<\/a>"],[97.590361445783,48,"PatientRepo<\/a>"],[97.402597402597,35,"RDVRepo<\/a>"],[93.548387096774,9,"StatsRepo<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -259,7 +259,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[100,3,"StaticRepo::getConnexion<\/a>"],[100,1,"StaticRepo::testConnexion<\/a>"],[85.714285714286,10,"StaticRepo::delNumeric<\/a>"],[80.555555555556,40,"StaticRepo::checkParam<\/a>"],[100,2,"MedecinRepo::getById<\/a>"],[88.888888888889,3,"MedecinRepo::add<\/a>"],[100,2,"MedecinRepo::delete<\/a>"],[100,6,"MedecinRepo::search<\/a>"],[100,2,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"MedecinRepo::update<\/a>"],[100,2,"PatientRepo::getById<\/a>"],[96.774193548387,16,"PatientRepo::add<\/a>"],[96.875,18,"PatientRepo::update<\/a>"],[100,2,"PatientRepo::delete<\/a>"],[100,3,"PatientRepo::updateMedecinTraitant<\/a>"],[100,6,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,2,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getForMonth<\/a>"],[100,2,"RDVRepo::getByDate<\/a>"],[100,2,"RDVRepo::delete<\/a>"],[100,6,"RDVRepo::add<\/a>"],[100,2,"RDVRepo::updateDateTime<\/a>"],[100,3,"RDVRepo::getByPatientAndDate<\/a>"],[86.666666666667,5,"RDVRepo::getAll<\/a>"],[100,2,"RDVRepo::getByMonth<\/a>"],[92.592592592593,8,"StatsRepo::getAgePatient<\/a>"],[100,1,"StatsRepo::getRDVStat<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,3,"StaticRepo::getConnexion<\/a>"],[100,1,"StaticRepo::testConnexion<\/a>"],[85.714285714286,10,"StaticRepo::delNumeric<\/a>"],[80.555555555556,40,"StaticRepo::checkParam<\/a>"],[100,2,"MedecinRepo::getById<\/a>"],[88.888888888889,3,"MedecinRepo::add<\/a>"],[100,2,"MedecinRepo::delete<\/a>"],[100,6,"MedecinRepo::search<\/a>"],[100,2,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"MedecinRepo::update<\/a>"],[100,2,"PatientRepo::getById<\/a>"],[96.774193548387,16,"PatientRepo::add<\/a>"],[96.875,18,"PatientRepo::update<\/a>"],[100,2,"PatientRepo::delete<\/a>"],[100,3,"PatientRepo::updateMedecinTraitant<\/a>"],[100,6,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,2,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getForMonth<\/a>"],[100,2,"RDVRepo::getByDate<\/a>"],[100,2,"RDVRepo::delete<\/a>"],[100,7,"RDVRepo::add<\/a>"],[100,3,"RDVRepo::updateDateTime<\/a>"],[100,3,"RDVRepo::getByPatientAndDate<\/a>"],[86.666666666667,5,"RDVRepo::getAll<\/a>"],[100,2,"RDVRepo::getByMonth<\/a>"],[100,8,"RDVRepo::isPossible<\/a>"],[92.592592592593,8,"StatsRepo::getAgePatient<\/a>"],[100,1,"StatsRepo::getRDVStat<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/coverage/index.html b/coverage/index.html index 57d4695..9d12a80 100755 --- a/coverage/index.html +++ b/coverage/index.html @@ -43,21 +43,21 @@ Total
-
- 93.98% covered (success) +
+ 94.29% covered (success)
-
93.98%
-
250 / 266
+
94.29%
+
264 / 280
-
- 75.86% covered (warning) +
+ 76.67% covered (warning)
-
75.86%
-
22 / 29
+
76.67%
+
23 / 30
0.00% covered (danger) @@ -71,21 +71,21 @@ repos
-
- 96.67% covered (success) +
+ 96.88% covered (success)
-
96.67%
-
203 / 210
+
96.88%
+
217 / 224
-
- 80.00% covered (warning) +
+ 80.77% covered (warning)
-
80.00%
-
20 / 25
+
80.77%
+
21 / 26
0.00% covered (danger) @@ -136,7 +136,7 @@ High: 90% to 100%

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 18:13:26 UTC 2016. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 19:23:14 UTC 2016.

diff --git a/coverage/repos/MedecinRepo.php.html b/coverage/repos/MedecinRepo.php.html index a976f66..dbde13b 100755 --- a/coverage/repos/MedecinRepo.php.html +++ b/coverage/repos/MedecinRepo.php.html @@ -61,13 +61,13 @@
6 / 7
CRAP
-
- 97.06% covered (success) +
+ 96.97% covered (success)
-
97.06%
-
33 / 34
+
96.97%
+
32 / 33
@@ -90,13 +90,13 @@
6 / 7
17
-
- 97.06% covered (success) +
+ 96.97% covered (success)
-
97.06%
-
33 / 34
+
96.97%
+
32 / 33
@@ -159,11 +159,11 @@
100.00%
-
4 / 4
+
3 / 3
-  search +  search
100.00% covered (success) @@ -184,7 +184,7 @@ -  getPatients +  getPatients
100.00% covered (success) @@ -205,7 +205,7 @@ -  getAll +  getAll
100.00% covered (success) @@ -226,7 +226,7 @@ -  update +  update
100.00% covered (success) @@ -295,58 +295,56 @@         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]); -     } +         $req = StaticRepo::getConnexion()->prepare('DELETE FROM Medecin WHERE Id = :id'); +         return $req->execute(['id' => $idMedecin]); +     } + +     public static function search($nom, $prenom){ -     public static function search($nom, $prenom){ +         if( !StaticRepo::checkParam($prenom,'String45') | !StaticRepo::checkParam($nom,'String45') ) return false; -         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() ); -     } +         // 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){ -     public static function getPatients($idMedecin){ +         if(!StaticRepo::checkParam($idMedecin,'Numeric')) return false; -         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()); -     } +         $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(){ -     public static function getAll(){ +         $req = StaticRepo::getConnexion()->query('SELECT * FROM Medecin ORDER BY nom, prenom ASC'); -         $req = StaticRepo::getConnexion()->query('SELECT * FROM Medecin ORDER BY nom, prenom ASC'); +         return StaticRepo::delNumeric( $req->fetchAll() ); -         return StaticRepo::delNumeric( $req->fetchAll() ); +     } -     } - + +     public static function update($id, $nom, $prenom){ -     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 ]); -     } - - } +         $req = StaticRepo::getConnexion()->prepare("UPDATE Medecin SET Nom = :nom, Prenom = :prenom WHERE Id = :id"); +         return $req->execute([ ':nom' => strtoupper($nom), ':prenom' => $prenom, ':id' => $id ]); +     } + + } @@ -359,7 +357,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 18:13:26 UTC 2016. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 19:23:14 UTC 2016.

diff --git a/coverage/repos/PatientRepo.php.html b/coverage/repos/PatientRepo.php.html index f1b9cd8..d8e70e1 100755 --- a/coverage/repos/PatientRepo.php.html +++ b/coverage/repos/PatientRepo.php.html @@ -465,7 +465,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 18:13:26 UTC 2016. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 19:23:14 UTC 2016.

diff --git a/coverage/repos/RDVRepo.php.html b/coverage/repos/RDVRepo.php.html index 97e0c8a..9575432 100755 --- a/coverage/repos/RDVRepo.php.html +++ b/coverage/repos/RDVRepo.php.html @@ -51,23 +51,23 @@
0.00%
0 / 1
-
-
- 88.89% covered (warning) -
-
- -
88.89%
-
8 / 9
- CRAP
-
- 96.77% covered (success) +
+ 90.00% covered (success)
-
96.77%
-
60 / 62
+
90.00%
+
9 / 10
+ CRAP +
+
+ 97.40% covered (success) +
+
+ +
97.40%
+
75 / 77
@@ -80,23 +80,23 @@
0.00%
0 / 1
-
-
- 88.89% covered (warning) -
-
- -
88.89%
-
8 / 9
- 25
-
- 96.77% covered (success) +
+ 90.00% covered (success)
-
96.77%
-
60 / 62
+
90.00%
+
9 / 10
+ 35 +
+
+ 97.40% covered (success) +
+
+ +
97.40%
+
75 / 77
@@ -193,7 +193,7 @@
100.00%
1 / 1
- 6 + 7
100.00% covered (success) @@ -201,11 +201,11 @@
100.00%
-
12 / 12
+
13 / 13
-  updateDateTime +  updateDateTime
100.00% covered (success) @@ -214,7 +214,7 @@
100.00%
1 / 1
- 2 + 3
100.00% covered (success) @@ -222,11 +222,11 @@
100.00%
-
6 / 6
+
9 / 9
-  getByPatientAndDate +  getByPatientAndDate
100.00% covered (success) @@ -247,7 +247,7 @@ -  getAll +  getAll
0.00% covered (danger) @@ -268,7 +268,7 @@ -  getByMonth +  getByMonth
100.00% covered (success) @@ -288,6 +288,27 @@
7 / 7
+ +  isPossible +
+
+ 100.00% covered (success) +
+
+ +
100.00%
+
1 / 1
+ 8 +
+
+ 100.00% covered (success) +
+
+ +
100.00%
+
11 / 11
+ + @@ -306,11 +327,11 @@         public static function getById($id){ -         if(!StaticRepo::checkParam($id,'Integer')){return false;} +         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 ); +         $req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV WHERE RDV.id = :id'); +         $req->execute(['id' => $id]); +         return StaticRepo::delNumeric( $req->fetch(), true );     } @@ -328,12 +349,12 @@     public static function getByDate($date){ -         if(!StaticRepo::checkParam($date,'Date')){return false;} +         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()); +         $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){ @@ -348,83 +369,115 @@         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, $dateRdv, $duree){ +         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;} +     } -         if(!StaticRepo::checkParam($idRDV, 'Numeric')) return false; +     public static function updateDateTime($idRDV, $dateRdv, $duree){ -         $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 -         ]); -     } +         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;} -     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 = 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; -         } -         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() ); -     } - - } +             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; + +     } + + } @@ -437,7 +490,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 18:13:26 UTC 2016. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 19:23:14 UTC 2016.

diff --git a/coverage/repos/StatsRepo.php.html b/coverage/repos/StatsRepo.php.html index fd9296a..03735a0 100755 --- a/coverage/repos/StatsRepo.php.html +++ b/coverage/repos/StatsRepo.php.html @@ -220,7 +220,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 18:13:26 UTC 2016. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 19:23:14 UTC 2016.

diff --git a/coverage/repos/dashboard.html b/coverage/repos/dashboard.html index 4c448ba..6a1baf3 100755 --- a/coverage/repos/dashboard.html +++ b/coverage/repos/dashboard.html @@ -112,7 +112,7 @@ - getAll86% + getAll86% add88% @@ -130,7 +130,7 @@ - getAll5 + getAll5 add3 @@ -141,7 +141,7 @@
@@ -180,7 +180,7 @@ $(document).ready(function() { .yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,2,3,20], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,2,3,21], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -230,7 +230,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[97.058823529412,17,"MedecinRepo<\/a>"],[97.590361445783,48,"PatientRepo<\/a>"],[96.774193548387,25,"RDVRepo<\/a>"],[93.548387096774,9,"StatsRepo<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[96.969696969697,17,"MedecinRepo<\/a>"],[97.590361445783,48,"PatientRepo<\/a>"],[97.402597402597,35,"RDVRepo<\/a>"],[93.548387096774,9,"StatsRepo<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -254,7 +254,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[100,2,"MedecinRepo::getById<\/a>"],[88.888888888889,3,"MedecinRepo::add<\/a>"],[100,2,"MedecinRepo::delete<\/a>"],[100,6,"MedecinRepo::search<\/a>"],[100,2,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"MedecinRepo::update<\/a>"],[100,2,"PatientRepo::getById<\/a>"],[96.774193548387,16,"PatientRepo::add<\/a>"],[96.875,18,"PatientRepo::update<\/a>"],[100,2,"PatientRepo::delete<\/a>"],[100,3,"PatientRepo::updateMedecinTraitant<\/a>"],[100,6,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,2,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getForMonth<\/a>"],[100,2,"RDVRepo::getByDate<\/a>"],[100,2,"RDVRepo::delete<\/a>"],[100,6,"RDVRepo::add<\/a>"],[100,2,"RDVRepo::updateDateTime<\/a>"],[100,3,"RDVRepo::getByPatientAndDate<\/a>"],[86.666666666667,5,"RDVRepo::getAll<\/a>"],[100,2,"RDVRepo::getByMonth<\/a>"],[92.592592592593,8,"StatsRepo::getAgePatient<\/a>"],[100,1,"StatsRepo::getRDVStat<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,2,"MedecinRepo::getById<\/a>"],[88.888888888889,3,"MedecinRepo::add<\/a>"],[100,2,"MedecinRepo::delete<\/a>"],[100,6,"MedecinRepo::search<\/a>"],[100,2,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"MedecinRepo::update<\/a>"],[100,2,"PatientRepo::getById<\/a>"],[96.774193548387,16,"PatientRepo::add<\/a>"],[96.875,18,"PatientRepo::update<\/a>"],[100,2,"PatientRepo::delete<\/a>"],[100,3,"PatientRepo::updateMedecinTraitant<\/a>"],[100,6,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,2,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getForMonth<\/a>"],[100,2,"RDVRepo::getByDate<\/a>"],[100,2,"RDVRepo::delete<\/a>"],[100,7,"RDVRepo::add<\/a>"],[100,3,"RDVRepo::updateDateTime<\/a>"],[100,3,"RDVRepo::getByPatientAndDate<\/a>"],[86.666666666667,5,"RDVRepo::getAll<\/a>"],[100,2,"RDVRepo::getByMonth<\/a>"],[100,8,"RDVRepo::isPossible<\/a>"],[92.592592592593,8,"StatsRepo::getAgePatient<\/a>"],[100,1,"StatsRepo::getRDVStat<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/coverage/repos/index.html b/coverage/repos/index.html index 178a026..06f5434 100755 --- a/coverage/repos/index.html +++ b/coverage/repos/index.html @@ -44,21 +44,21 @@ Total
-
- 96.67% covered (success) +
+ 96.88% covered (success)
-
96.67%
-
203 / 210
+
96.88%
+
217 / 224
-
- 80.00% covered (warning) +
+ 80.77% covered (warning)
-
80.00%
-
20 / 25
+
80.77%
+
21 / 26
0.00% covered (danger) @@ -72,13 +72,13 @@ MedecinRepo.php
-
- 97.06% covered (success) +
+ 96.97% covered (success)
-
97.06%
-
33 / 34
+
96.97%
+
32 / 33
85.71% covered (warning) @@ -128,21 +128,21 @@ RDVRepo.php
-
- 96.77% covered (success) +
+ 97.40% covered (success)
-
96.77%
-
60 / 62
-
-
- 88.89% covered (warning) +
97.40%
+
75 / 77
+
+
+ 90.00% covered (success)
-
88.89%
-
8 / 9
+
90.00%
+
9 / 10
0.00% covered (danger) @@ -193,7 +193,7 @@ High: 90% to 100%

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 18:13:26 UTC 2016. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.1 and PHPUnit 5.1.3 at Sun Jan 3 19:23:14 UTC 2016.

diff --git a/repositories/repos/MedecinRepo.php b/repositories/repos/MedecinRepo.php index c53c489..fca22cd 100755 --- a/repositories/repos/MedecinRepo.php +++ b/repositories/repos/MedecinRepo.php @@ -42,8 +42,6 @@ class MedecinRepo 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]); } diff --git a/repositories/repos/RDVRepo.php b/repositories/repos/RDVRepo.php index 3db4ca5..5c10c68 100755 --- a/repositories/repos/RDVRepo.php +++ b/repositories/repos/RDVRepo.php @@ -36,7 +36,7 @@ class RDVRepo 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 = 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()); } @@ -53,6 +53,8 @@ class RDVRepo 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)'); @@ -72,6 +74,12 @@ class RDVRepo 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, @@ -129,4 +137,28 @@ class RDVRepo 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; + + } + } diff --git a/test.php b/test.php index dd1f2d8..ef172ac 100755 --- a/test.php +++ b/test.php @@ -14,7 +14,7 @@ $rdv = new RDV(); getSVG(['mois' => '10/2015']); + var_dump(RDVRepo::isPossible("2015-12-20 13:40:00",30,60)); ?> \ No newline at end of file diff --git a/test/RDVRepoTest.php b/test/RDVRepoTest.php index 89ea33b..80912a3 100755 --- a/test/RDVRepoTest.php +++ b/test/RDVRepoTest.php @@ -23,6 +23,7 @@ class RDVRepoTest extends PHPUnit_Framework_TestCase $id = $this->repo->add(date('Y-m-d H:i:s',time()),30,2,1); $this->assertNotNull($id); $this->assertNotFalse($id); + $this->assertFalse($this->repo->add(date('Y-m-d H:i:s',time()),30,2,1)); $this->assertTrue($this->repo->delete($id)); $this->assertFalse($this->repo->add(date('Y-m-d H:i:s',time()),30,2,-1));