diff --git a/build/api/module/professor/statsController.php b/build/api/module/professor/statsController.php index 1566cef..5bdfdd4 100644 --- a/build/api/module/professor/statsController.php +++ b/build/api/module/professor/statsController.php @@ -21,22 +21,7 @@ class statsController{ /** @var professor $profRepo */ $profRepo = Repo::getRepo("professor"); - $VH = $profRepo->getVH($idProf); - - if(in_array($VH["idCat"],[1,3])){ - $VH["equiTD"] = $VH["VHTd"] + $VH["VHTp"] + 1.5*$VH["VHCours"]; - - if($VH["equiTD"] > $VH["du"]){ - $partTP = $VH["VHTp"] / $VH["equiTD"]; - $valReelleTP = $partTP * $VH["du"]; - $VH["equiTD"] = round(1.5*$VH["VHCours"] + $VH["VHTd"] + $valReelleTP + ($VH["VHTp"] - $valReelleTP)*(2/3),2); - } - - $VH["VHComp"] = round($VH["equiTD"] - $VH["du"],2); - $VH["VHComp"] < 0 ? 0 : $VH["VHComp"]; - }else{ - $VH["equiTD"] = $VH["VHTd"] + (2/3)*$VH["VHTp"] + 1.5*$VH["VHCours"]; - } + $VH = $profRepo->getWithVH($idProf); return ["data" => $VH]; } diff --git a/build/api/module/professorController.php b/build/api/module/professorController.php index b7f0b69..6f41d84 100644 --- a/build/api/module/professorController.php +++ b/build/api/module/professorController.php @@ -16,34 +16,6 @@ use error\core\Err; class professorController{ - - private static function proccess_vh(array &$vh_prof){ - - /* (1) If not in category 1 nor 3 -> equivalentTD = TD + 2/3.TP + 1.5.COURS */ - if( !in_array($vh_prof['idCat'], [1,3]) ) - return $vh_prof['equiTD'] = $vh_prof['VHTd'] + (2/3)*$vh_prof['VHTp'] + 1.5*$vh_prof['VHCours']; - // exited because of 'return' statement - - - /* (2) Else (cat = 1 or 3) -> equivalentTD = TD + TP + 1.5.COURS */ - $vh_prof['equiTD'] = $vh_prof['VHTd'] + $vh_prof['VHTp'] + 1.5*$vh_prof['VHCours']; - - /* (3) If equivalentTD exceeds HeuresDues */ - if($vh_prof['equiTD'] > $vh_prof['du']){ - - /* (3.1) @valTP = HeuresDues.(TP / equivalentTD) */ - $valTP = $vh_prof['du'] * ( $vh_prof['VHTp'] / $vh_prof['equiTD'] ); - /* (3.2) equivalentTD = 1.5*COURS + TD + @valTP + (TP-@valTP) */ - $vh_prof['equiTD'] = round(1.5*$vh_prof['VHCours'] + $vh_prof['VHTd'] + $valTP + ($vh_prof['VHTp'] - $valTP)*(2/3), 2); - - } - - /* (4) VH comp */ - $vh_prof['VHComp'] = round($vh_prof['equiTD'] - $vh_prof['du'], 2); - $vh_prof['VHComp'] = ( $vh_prof['VHComp'] < 0 ) ? 0 : $vh_prof['VHComp']; - } - - /* (1) Returns 1 or all professors * * @prof_id [OPT] The professor UID @@ -63,16 +35,13 @@ class professorController{ /* (1) If with VH data ---------------------------------------------------------*/ - if( is_string($with_vh) && $with_vh == '1' ){ + + if( $with_vh == 1 ){ /* (1) Get All professors or 1 by its id (if set) */ $fetched = $prof_repo->getWithVH($prof_id); - /* (2) Process VH */ - foreach($fetched as &$vh_prof) - self::proccess_vh($vh_prof); - - /* (3) Return data */ + /* (2) Return data */ return ['professors' => $fetched]; } diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index 9a1e73b..28e4daa 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -286,7 +286,28 @@ class professor extends Repo_i { if( $fetched === false ) return []; - /* (7) Return data */ + /* (7) Compute additional data */ + + foreach ($fetched as &$prof){ + /* (1) If not in category 1 nor 3 -> equivalentTD = TD + 2/3.TP + 1.5.COURS */ + if(in_array($prof["idCat"],[1,3])){ + $prof["equiTD"] = $prof["VHTd"] + $prof["VHTp"] + 1.5*$prof["VHCours"]; + + if($prof["equiTD"] > $prof["hoursToDo"]){ + $partTP = $prof["VHTp"] / $prof["equiTD"]; + $valReelleTP = $partTP * $prof["hoursToDo"]; + $prof["equiTD"] = round(1.5*$prof["VHCours"] + $prof["VHTd"] + $valReelleTP + ($prof["VHTp"] - $valReelleTP)*(2/3),2); + } + + $prof['VHComp'] = round($prof['equiTD'] - $prof['hoursToDo'], 2); + $prof['VHComp'] = ( $prof['VHComp'] < 0 ) ? 0 : $prof['VHComp']; + }else{ + $VH["equiTD"] = $prof["VHTd"] + (2/3)*$prof["VHTp"] + 1.5*$prof["VHCours"]; + $prof['VHComp'] = null; + } + } + + /* (8) Return data */ return $fetched; } @@ -309,39 +330,4 @@ class professor extends Repo_i { } - - - - /* (9) Returns a professor's statistic data - * - * @return data Professor data - * - ---------------------------------------------------------*/ - public function getVH(int $id) : array{ - - /* (1) Prepare Statement */ - $st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, Cat.idCategorie idCat, Prof.hoursToDo du - FROM Professeur Prof, Categorie Cat, - (SELECT IFNULL(SUM(Cours.volume),0) VHCours, Prof.idProfesseur idProf FROM Professeur Prof LEFT JOIN Cours ON Prof.idProfesseur = Cours.Professeur_idProfesseur GROUP BY Prof.idProfesseur) VHCours, - (SELECT IFNULL(SUM(TD.volume),0) VHTd , Prof.idProfesseur idProf FROM Professeur Prof LEFT JOIN TD ON TD.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHTd, - (SELECT IFNULL(SUM(TP.volume),0) VHTp, Prof.idProfesseur idProf FROM Professeur Prof LEFT JOIN TP ON TP.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHTp - WHERE - Prof.idProfesseur = :idProf AND - Prof.Categorie_idCategorie = Cat.idCategorie AND - VHCours.idProf = Prof.idProfesseur AND - VHTp.idProf = Prof.idProfesseur AND - VHTd.idProf = Prof.idProfesseur;"); - - /* (2) Bind params and execute */ - $success = $st->execute([ ':idProf' => $id ]); - - /* (3) Manage error */ - if( !$success ) - return []; - - /* (4) Return data */ - return $st->fetch() ?: []; - - } - } \ No newline at end of file