diff --git a/build/api/module/Excel.php b/build/api/module/Excel.php index 842bd5d..ec842ff 100644 --- a/build/api/module/Excel.php +++ b/build/api/module/Excel.php @@ -54,6 +54,8 @@ class Excel $allUE = []; //array containing all the formations $allFormations = []; + //can the current UE have a default formation + $isDefaultFormationPossible = false; /* * declare the lambda that will add finalized UE to the array @@ -78,11 +80,12 @@ class Excel * declaring the lambda tha twill extract the list of formation involved in the group */ $getFormations = function(?string $group) use (&$formation,&$allFormations) : array{ - if(!$group){ + $group = trim($group); + if($group == ""){ if(!isset($allFormations[$formation])){ $allFormations[$formation] = [ "name" => $formation, - "internal" => 1 + "internal" => strpos($formation,"Info") !== false ? true : false ]; } return [$formation]; @@ -129,7 +132,7 @@ class Excel }; $exitWithNullException = function(){ - exit(json_encode(["error" => true, "message" => "NullCelException"])); + exit(json_encode(["error" => true, "message" => "NullCellException"])); }; //starting the iteration @@ -167,6 +170,8 @@ class Excel $UE["TpVH"] = ($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: 0.0; $UE["TpGroup"] = ($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: 0; + $UE["defaultFormation"] = null; + $isDefaultFormationPossible = true; continue; } @@ -178,33 +183,60 @@ class Excel ]; //compute Course - if (($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()){ - $UE["groups"]["Course"][] = [ + if (is_numeric(($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue())){ + $group = [ "VH" => ($UESpreadsheet->getCellByColumnAndRow(5,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(), "internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "professor" => ($UESpreadsheet->getCellByColumnAndRow(7,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null ]; + + if(count($group["formations"]) == 1 and $isDefaultFormationPossible and ($UE["defaultFormation"] == null or $UE["defaultFormation"] == $group["formations"][0])){ + $UE["defaultFormation"] = $group["formations"][0]; + }else{ + $UE["defaultFormation"] = null; + $isDefaultFormationPossible = false; + } + + $UE["groups"]["Course"][] = $group; } //compute TDs - if(($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()){ - $UE["groups"]["TD"][] = [ + if(is_numeric(($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue())){ + $group = [ "VH" => ($UESpreadsheet->getCellByColumnAndRow(8,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(), "internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(9,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), - "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), + "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(9,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "professor" => ($UESpreadsheet->getCellByColumnAndRow(10,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null ]; + + if(count($group["formations"]) == 1 and $isDefaultFormationPossible and ($UE["defaultFormation"] == null or $UE["defaultFormation"] == $group["formations"][0])){ + $UE["defaultFormation"] = $group["formations"][0]; + }else{ + $UE["defaultFormation"] = null; + $isDefaultFormationPossible = false; + } + + $UE["groups"]["TD"][] = $group; } //compute TPs - if(($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()){ - $UE["groups"]["TP"][] = [ + if(is_numeric(($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue())){ + $group = [ "VH" => ($UESpreadsheet->getCellByColumnAndRow(11,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue(), "internalStudentPart" => $getInternalStudentPart(($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), - "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(6,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), + "formations" => $getFormations(($UESpreadsheet->getCellByColumnAndRow(12,$row->getRowIndex()) ?? $exitWithNullException())->getCalculatedValue()), "professor" => ($UESpreadsheet->getCellByColumnAndRow(13,$row->getRowIndex()) ?? $exitWithNullException())->getValue() ?: null ]; + + if(count($group["formations"]) == 1 and $isDefaultFormationPossible and ($UE["defaultFormation"] == null or $UE["defaultFormation"] == $group["formations"][0])){ + $UE["defaultFormation"] = $group["formations"][0]; + }else{ + $UE["defaultFormation"] = null; + $isDefaultFormationPossible = false; + } + + $UE["groups"]["TP"][] = $group; } } @@ -307,12 +339,22 @@ class Excel $tpRepo = Repo::getRepo("tp"); foreach ($allUE as $codeUE => $UE){ + + if($UE["defaultFormation"]){ + $UE["defaultFormationId"] = $allFormations[$UE["defaultFormation"]]["dbId"]; + }else{ + $UE["defaultFormationId"] = null; + } + $ueRepo->create(utf8_decode($codeUE), utf8_decode($UE["name"]), $UE["required"] == "OBL", $UE["CourseVH"], $UE["TdVH"], - $UE["TpVH"]); + $UE["TpVH"], + false, + $UE["defaultFormationId"] + ); if(isset($UE["groups"])){ foreach ($UE["groups"] as $type => $groups){ foreach ($groups as $group){ diff --git a/build/api/module/Formation.php b/build/api/module/Formation.php new file mode 100644 index 0000000..51e87cd --- /dev/null +++ b/build/api/module/Formation.php @@ -0,0 +1,27 @@ + $repo->getStat($idForm)]; + } + +} \ No newline at end of file diff --git a/build/database/repo/formation.php b/build/database/repo/formation.php index 8396ef5..da08037 100644 --- a/build/database/repo/formation.php +++ b/build/database/repo/formation.php @@ -42,4 +42,24 @@ class formation extends Repo_i { ]); } + public function getStat(int $id) :array{ + $st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, (VHCours + VHTd + VHTp) VHTotal, Form.isInternal isInternal + FROM Formation Form, + (SELECT IFNULL(SUM(C.volume),0) VHCours, GC.Formation_idFormation idForm FROM GroupeCours GC LEFT JOIN Cours C ON GC.Cours_idCours = C.idCours GROUP BY GC.Formation_idFormation) VHCours, + (SELECT IFNULL(SUM(T.volume),0) VHTd, GTD.Formation_idFormation idForm FROM GroupeTD GTD LEFT JOIN TD T ON GTD.TD_idTD = T.idTD GROUP BY GTD.Formation_idFormation) VHTd, + (SELECT IFNULL(SUM(T2.volume),0) VHTp, GTP.Formation_idFormation idForm FROM GroupeTP GTP LEFT JOIN TP T2 ON GTP.TP_idTP = T2.idTP GROUP BY GTP.Formation_idFormation) VHTp + WHERE + Form.idFormation = :idForm AND + VHCours.idForm = Form.idFormation AND + VHTp.idForm = Form.idFormation AND + VHTd.idForm = Form.idFormation; + "); + + $st->execute([ + "idForm" => $id + ]); + + return $st->fetch() ?: []; + } + } \ No newline at end of file diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index 3d3e535..c2f8afa 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -102,7 +102,7 @@ class professor extends Repo_i { "idProf" => $id ]); - return $st->fetch(); + return $st->fetch() ?: []; } } \ No newline at end of file diff --git a/build/database/repo/ue.php b/build/database/repo/ue.php index 4b3407b..5998716 100644 --- a/build/database/repo/ue.php +++ b/build/database/repo/ue.php @@ -13,9 +13,9 @@ use database\core\Repo_i; class ue extends Repo_i { - public function create(string $code, string $label, bool $required, float $volumeCours, float $volumeTD, float $volumeTP, bool $disabled = false) : int { - $st = $this->pdo->prepare("INSERT INTO UE(code, label, required, volumeCours, volumeTD, volumeTP, disabled) - VALUE(:code, :label, :required, :volCours, :volTD, :volTP, :disabled) "); + public function create(string $code, string $label, bool $required, float $volumeCours, float $volumeTD, float $volumeTP, bool $disabled = false, ?int $defaultFormation = null) : int { + $st = $this->pdo->prepare("INSERT INTO UE(code, label, required, volumeCours, volumeTD, volumeTP, disabled, Formation_idFormation) + VALUE(:code, :label, :required, :volCours, :volTD, :volTP, :disabled, :idFormation) "); $st->execute([ "code" => $code, @@ -24,7 +24,8 @@ class ue extends Repo_i { "volCours" => $volumeCours, "volTD" => $volumeTD, "volTP" => $volumeTP, - "disabled" => $disabled ? 1 : 0 + "disabled" => $disabled ? 1 : 0, + "idFormation" => $defaultFormation ]); return $this->pdo->lastInsertId();