From b1bf05541d10b42b1ef95c4c1312dde047dd9f27 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Mon, 5 Mar 2018 20:30:05 +0100 Subject: [PATCH] fixed encoding + implemented incoherence detection --- .../module/departement/errorsController.php | 25 +++++ build/api/module/excelController.php | 20 ++-- build/database/repo/category.php | 7 +- build/database/repo/departement.php | 91 +++++++++++++++++++ config/modules.json | 11 +++ 5 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 build/api/module/departement/errorsController.php create mode 100644 build/database/repo/departement.php diff --git a/build/api/module/departement/errorsController.php b/build/api/module/departement/errorsController.php new file mode 100644 index 0000000..9cec7e6 --- /dev/null +++ b/build/api/module/departement/errorsController.php @@ -0,0 +1,25 @@ + $repo->getErrors()]; + } + +} \ No newline at end of file diff --git a/build/api/module/excelController.php b/build/api/module/excelController.php index 6f6e1e2..3be39ea 100644 --- a/build/api/module/excelController.php +++ b/build/api/module/excelController.php @@ -301,15 +301,15 @@ class excelController foreach ($allProf as $initials => &$prof){ //create or update the professor category - $catRepo->createOrUpdate($prof["categoryIndex"], utf8_decode($prof["categoryLabel"])); + $catRepo->create($prof["categoryIndex"], $prof["categoryLabel"]); //create the professor, as some names are missing, we replace them by something else if(!$prof["lastName"]) $prof["lastName"] = "missingLastName"; if(!$prof["firstName"]) $prof["firstName"] = "missingFirstName"; - $prof["dbId"] = $profRepo->exists(utf8_decode($prof["lastName"]), utf8_decode($prof["firstName"])); + $prof["dbId"] = $profRepo->exists($prof["lastName"], $prof["firstName"]); if(!$prof["dbId"]){ - $prof["dbId"] = $profRepo->create( utf8_decode($prof["lastName"]), utf8_decode($prof["firstName"]), $prof["categoryIndex"], $prof["hoursToDo"], $initials); + $prof["dbId"] = $profRepo->create( $prof["lastName"], $prof["firstName"], $prof["categoryIndex"], $prof["hoursToDo"], $initials); } } @@ -318,9 +318,9 @@ class excelController $formRepo = Repo::getRepo("formation"); foreach ($allFormations as &$form){ - $form["dbId"] = $formRepo->exists( utf8_decode($form["name"])); + $form["dbId"] = $formRepo->exists( $form["name"]); if(!$form["dbId"]){ - $form["dbId"] = $formRepo->create( utf8_decode($form["name"]), $form["internal"]); + $form["dbId"] = $formRepo->create( $form["name"], $form["internal"]); } } @@ -346,8 +346,8 @@ class excelController $UE["defaultFormationId"] = null; } - $ueRepo->create(utf8_decode($codeUE), - utf8_decode($UE["name"]), + $ueRepo->create($codeUE, + $UE["name"], $UE["required"] == "OBL", $UE["CourseVH"], $UE["TdVH"], @@ -367,19 +367,19 @@ class excelController switch ($type){ case "Course": - $coursRepo->create( utf8_decode($codeUE), + $coursRepo->create( $codeUE, $allProf[$group["professor"]]["dbId"], $group["VH"], $formations); break; case "TD": - $tdRepo->create(utf8_decode($codeUE), + $tdRepo->create($codeUE, $allProf[$group["professor"]]["dbId"], $group["VH"], $formations); break; case "TP": - $tpRepo->create(utf8_decode($codeUE), + $tpRepo->create($codeUE, $allProf[$group["professor"]]["dbId"], $group["VH"], $formations); diff --git a/build/database/repo/category.php b/build/database/repo/category.php index 9cf8a8d..71fd68f 100644 --- a/build/database/repo/category.php +++ b/build/database/repo/category.php @@ -13,14 +13,15 @@ use database\core\Repo_i; class category extends Repo_i{ - public function createOrUpdate(int $id, string $label){ + public function create(int $id, string $label) : bool{ //create the category or update the label - $st = $this->pdo->prepare("INSERT INTO Categorie (idCategorie, labelCategorie) VALUES (:id, :label) ON DUPLICATE KEY UPDATE labelCategorie = :label;"); + $st = $this->pdo->prepare("INSERT INTO Categorie (idCategorie, labelCategorie) VALUE (:id, :label)"); - $st->execute([ + return $st->execute([ "id" => $id, "label" => $label ]); + } public function delete(int $id) :bool{ diff --git a/build/database/repo/departement.php b/build/database/repo/departement.php new file mode 100644 index 0000000..de9d1e6 --- /dev/null +++ b/build/database/repo/departement.php @@ -0,0 +1,91 @@ +pdo->prepare(" + (SELECT 'NO_FORMATION_ASSIGNED' errorType, 'Cours' entityType, idCours id FROM Cours WHERE idCours NOT IN (SELECT Cours_idCours FROM GroupeCours)) + UNION + (SELECT 'NO_FORMATION_ASSIGNED' errorType, 'TD' entityType, idTD id FROM TD WHERE idTD NOT IN (SELECT TD_idTD FROM GroupeTD)) + UNION + (SELECT 'NO_FORMATION_ASSIGNED' errorType, 'TP' entityType, idTP id FROM TP WHERE idTP NOT IN (SELECT TP_idTP FROM GroupeTP))"); + + $GroupWithoutFormation->execute([]); + + $results = array_merge($results,$GroupWithoutFormation->fetchAll()); + + /* (2) Find Groups without a professor bound */ + + $GroupWithoutProfessor = $this->pdo->prepare(" + (SELECT 'NO_PROFESSOR_ASSIGNED' errorType, 'Cours' entityType, idCours id FROM Cours WHERE Professeur_idProfesseur IS NULL) + UNION + (SELECT 'NO_PROFESSOR_ASSIGNED' errorType, 'TD' entityType, idTD id FROM TD WHERE Professeur_idProfesseur IS NULL) + UNION + (SELECT 'NO_PROFESSOR_ASSIGNED' errorType, 'TP' entityType, idTP id FROM TP WHERE Professeur_idProfesseur IS NULL)"); + + $GroupWithoutProfessor->execute([]); + + $results = array_merge($results,$GroupWithoutProfessor->fetchAll()); + + /* (3) Find Groups a null VH */ + + $GroupWithNullVH = $this->pdo->prepare(" + (SELECT 'NULL_VH' errorType, 'Cours' entityType, idCours id FROM Cours WHERE volume = 0) + UNION + (SELECT 'NULL_VH' errorType, 'TD' entityType, idTD id FROM TD WHERE volume = 0) + UNION + (SELECT 'NULL_VH' errorType, 'TP' entityType, idTP id FROM TP WHERE volume = 0)"); + + $GroupWithNullVH->execute([]); + + $results = array_merge($results,$GroupWithNullVH->fetchAll()); + + /* (4) Find UE with an incorrect VH in the groups compared to what's supposed to be */ + + $UEWithIncorrectGroupVH = $this->pdo->prepare(" + (SELECT 'UNEQUIVALENT_VH' errorType, 'Cours' entityType, U.code + FROM UE U + WHERE + 0 != (SELECT MOD(SUM(volume),U.volumeCours) modCours FROM Cours WHERE UE_code = U.code GROUP BY Cours.UE_code) + ) + + UNION + + (SELECT 'UNEQUIVALENT_VH' errorType, 'TD' entityType, U.code + FROM UE U + WHERE + 0 != (SELECT MOD(SUM(volume),U.volumeTD) modCours FROM TD WHERE UE_code = U.code GROUP BY TD.UE_code) + ) + + UNION + + (SELECT 'UNEQUIVALENT_VH' errorType, 'TP' entityType, U.code + FROM UE U + WHERE + 0 != (SELECT MOD(SUM(volume),U.volumeTP) modCours FROM TP WHERE UE_code = U.code GROUP BY TP.UE_code) + )"); + + $UEWithIncorrectGroupVH->execute([]); + + $results = array_merge($results,$UEWithIncorrectGroupVH->fetchAll()); + + return $results; + } + +} \ No newline at end of file diff --git a/config/modules.json b/config/modules.json index 5b96093..ab1f435 100644 --- a/config/modules.json +++ b/config/modules.json @@ -59,6 +59,17 @@ } }, + "departement":{ + "errors":{ + "GET": { + "des": "Get the list of incoherence of the department", + "per": [], + "par": { + } + } + } + }, + "professor":{ "POST": {