fix professor controller and moved equitd computation to repo
This commit is contained in:
parent
dbbb0839ea
commit
4676df2bff
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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<int> [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];
|
||||
|
||||
}
|
||||
|
|
|
@ -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<array> 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() ?: [];
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue