From 58d0a5ee14efcfca0c051cd5903dcba958c70448 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Tue, 27 Feb 2018 18:24:49 +0100 Subject: [PATCH 1/3] fix mising formations and groups --- build/api/module/Excel.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/build/api/module/Excel.php b/build/api/module/Excel.php index 7540023..488d164 100644 --- a/build/api/module/Excel.php +++ b/build/api/module/Excel.php @@ -72,7 +72,15 @@ 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) return [$formation]; + if(!$group){ + if(!isset($allFormations[$formation])){ + $allFormations[$formation] = [ + "name" => $formation, + "internal" => 1 + ]; + } + return [$formation]; + } //replace the generic "INFO" keyword by the actual formation $group = str_replace("INFO",$formation,$group); @@ -280,9 +288,9 @@ class Excel foreach ($UE["groups"] as $type => $groups){ foreach ($groups as $group){ $formations = []; - foreach ($group["formations"] as $form){ - if(isset($allFormations[$form]["dbId"])){ - $formations[] = $allFormations[$form]["dbId"]; + foreach ($group["formations"] as $format){ + if(isset($allFormations[$format]["dbId"])){ + $formations[] = $allFormations[$format]["dbId"]; } } @@ -306,14 +314,12 @@ class Excel $formations); break; } + } } - } } - - return [ 'data' => ["professors" => $allProf, "formations" => $allFormations, "UEs" => $allUE ] ]; }catch (Exception $e){ return [ 'error' => new Error(Err::UnknownError) ]; From fd9357fdba4576a509d92e940d1b0d4925cf1418 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Tue, 27 Feb 2018 17:22:08 +0100 Subject: [PATCH 2/3] Implemented TD Equivalent Computing for the professors --- build/api/module/Professor/Stats.php | 41 ++++++++++++++++++++++++++++ build/database/repo/professor.php | 19 +++++++++++++ config/modules.json | 12 ++++++++ 3 files changed, 72 insertions(+) create mode 100644 build/api/module/Professor/Stats.php diff --git a/build/api/module/Professor/Stats.php b/build/api/module/Professor/Stats.php new file mode 100644 index 0000000..9098481 --- /dev/null +++ b/build/api/module/Professor/Stats.php @@ -0,0 +1,41 @@ + $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"]; + } + + return ["data" => $VH]; + } + +} \ No newline at end of file diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index 433d58d..f5aecfa 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -86,4 +86,23 @@ class professor extends Repo_i { ]); } + public function getVH(int $id) : array{ + $st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, Cat.idCategorie idCat, Prof.hoursToDo du + FROM Professeur Prof, Categorie Cat, + (SELECT SUM(C.volume) VHCours , Prof.idProfesseur idProf FROM Cours C, Professeur Prof WHERE C.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHCours, + (SELECT SUM(T.volume) VHTd , Prof.idProfesseur idProf FROM TD T, Professeur Prof WHERE T.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHTd, + (SELECT SUM(T2.volume) VHTp, Prof.idProfesseur idProf FROM TP T2 , Professeur Prof WHERE T2.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;"); + $st->execute([ + "idProf" => $id + ]); + + return $st->fetch(); + } + } \ No newline at end of file diff --git a/config/modules.json b/config/modules.json index cd5aded..c0901a1 100644 --- a/config/modules.json +++ b/config/modules.json @@ -70,6 +70,18 @@ } }, + "Professor":{ + "Stats": { + "GET":{ + "des": "Get statistics of the professor", + "per": [], + "par":{ + "URL0": {"des" : "Id of the professor", "typ": "id", "ren": "idProf", "opt" : false} + } + } + } + }, + "a": { "b": { From c0bb4541a7b0009de13d32bf6e51affa280a5b6d Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 27 Feb 2018 20:41:36 +0100 Subject: [PATCH 3/3] Refactor Repo + Fix TD Equivalent --- build/api/module/Excel.php | 75 +++++++++----- build/api/module/Professor/Stats.php | 6 +- build/api/module/admin.php | 142 --------------------------- build/database/core/Repo.php | 22 +---- build/database/repo/professor.php | 6 +- config/modules.json | 50 ++-------- 6 files changed, 73 insertions(+), 228 deletions(-) delete mode 100644 build/api/module/admin.php diff --git a/build/api/module/Excel.php b/build/api/module/Excel.php index 488d164..842bd5d 100644 --- a/build/api/module/Excel.php +++ b/build/api/module/Excel.php @@ -11,6 +11,12 @@ namespace api\module; use database\core\Repo; use database\core\Repo_i; +use database\repo\category; +use database\repo\cours; +use database\repo\professor; +use database\repo\td; +use database\repo\tp; +use database\repo\ue; use error\core\Err; use error\core\Error; use PhpOffice\PhpSpreadsheet\Exception; @@ -254,36 +260,59 @@ class Excel */ //professors + + /** @var professor $profRepo */ + $profRepo = Repo::getRepo("professor"); + + /** @var category $catRepo */ + $catRepo = Repo::getRepo("category"); + foreach ($allProf as $initials => &$prof){ //create or update the professor category - Repo::request("category", "createOrUpdate", $prof["categoryIndex"], utf8_decode($prof["categoryLabel"])); + $catRepo->createOrUpdate($prof["categoryIndex"], utf8_decode($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"] = Repo::request("professor", "exists", utf8_decode($prof["lastName"]), utf8_decode($prof["firstName"])); + $prof["dbId"] = $profRepo->exists(utf8_decode($prof["lastName"]), utf8_decode($prof["firstName"])); if(!$prof["dbId"]){ - $prof["dbId"] = Repo::request("professor", "create", utf8_decode($prof["lastName"]), utf8_decode($prof["firstName"]), $prof["categoryIndex"], $prof["hoursToDo"], $initials); + $prof["dbId"] = $profRepo->create( utf8_decode($prof["lastName"]), utf8_decode($prof["firstName"]), $prof["categoryIndex"], $prof["hoursToDo"], $initials); } } //formation and retreive the databse IDs + /** @var \database\repo\formation $formRepo */ + $formRepo = Repo::getRepo("formation"); + foreach ($allFormations as &$form){ - $form["dbId"] = Repo::request("formation","exists", utf8_decode($form["name"])); + $form["dbId"] = $formRepo->exists( utf8_decode($form["name"])); if(!$form["dbId"]){ - $form["dbId"] = Repo::request("formation", "create", utf8_decode($form["name"]), $form["internal"]); + $form["dbId"] = $formRepo->create( utf8_decode($form["name"]), $form["internal"]); } } //UEs and corresponding groups + + /** @var ue $ueRepo */ + $ueRepo = Repo::getRepo("ue"); + + /** @var cours $coursRepo */ + $coursRepo = Repo::getRepo("cours"); + + /** @var td $tdRepo */ + $tdRepo = Repo::getRepo("td"); + + /** @var tp $tpRepo */ + $tpRepo = Repo::getRepo("tp"); + foreach ($allUE as $codeUE => $UE){ - Repo::request("ue","create", utf8_decode($codeUE), - utf8_decode($UE["name"]), - $UE["required"] == "OBL", - $UE["CourseVH"], - $UE["TdVH"], - $UE["TpVH"]); + $ueRepo->create(utf8_decode($codeUE), + utf8_decode($UE["name"]), + $UE["required"] == "OBL", + $UE["CourseVH"], + $UE["TdVH"], + $UE["TpVH"]); if(isset($UE["groups"])){ foreach ($UE["groups"] as $type => $groups){ foreach ($groups as $group){ @@ -296,22 +325,22 @@ class Excel switch ($type){ case "Course": - Repo::request("cours","create", utf8_decode($codeUE), - $allProf[$group["professor"]]["dbId"], - $group["VH"], - $formations); + $coursRepo->create( utf8_decode($codeUE), + $allProf[$group["professor"]]["dbId"], + $group["VH"], + $formations); break; case "TD": - Repo::request("td","create", utf8_decode($codeUE), - $allProf[$group["professor"]]["dbId"], - $group["VH"], - $formations); + $tdRepo->create(utf8_decode($codeUE), + $allProf[$group["professor"]]["dbId"], + $group["VH"], + $formations); break; case "TP": - Repo::request("tp","create", utf8_decode($codeUE), - $allProf[$group["professor"]]["dbId"], - $group["VH"], - $formations); + $tpRepo->create(utf8_decode($codeUE), + $allProf[$group["professor"]]["dbId"], + $group["VH"], + $formations); break; } diff --git a/build/api/module/Professor/Stats.php b/build/api/module/Professor/Stats.php index 9098481..f5b2524 100644 --- a/build/api/module/Professor/Stats.php +++ b/build/api/module/Professor/Stats.php @@ -10,6 +10,7 @@ namespace api\module\Professor; use database\core\Repo; +use database\repo\professor; class Stats { @@ -18,7 +19,10 @@ class Stats extract($args); //get data from the database - $VH = Repo::request("professor", "getVH", $idProf); + + /** @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"]; diff --git a/build/api/module/admin.php b/build/api/module/admin.php deleted file mode 100644 index 2724f37..0000000 --- a/build/api/module/admin.php +++ /dev/null @@ -1,142 +0,0 @@ - [OPT] UID de l'administrateur - * - * @return data Administrateurs correspondants - * - ---------------------------------------------------------*/ - public static function get($args){ - $id_admin = 0; - extract($args); - - /* (1) If @id_admin is set -> get by id - ---------------------------------------------------------*/ - if( is_numeric($id_admin) ){ - - /* (1) Search admin by id */ - $fetch_admin = Repo::request('admin', 'getById', $id_admin); - - /* (2) If not found -> return empty data */ - if( !$fetch_admin ) - return [ 'data' => [] ]; - - /* (3) Return fetched admin */ - return [ 'data' => [$fetch_admin] ]; - - - /* (2) Else -> get all - ---------------------------------------------------------*/ - }else - return [ 'data' => Repo::request('admin', 'getAll') ]; - - } - - - - /* (2) Creates a new administrator - * - * @username Identifiant de l'administrateur - * @mail Adresse mail de l'administrateur - * @password Mot de passe de l'administrateur - * - * @return admin Données de l'administrateur crée - * - ---------------------------------------------------------*/ - public static function post($args){ - $username = ""; - $mail = ""; - $password = ""; - extract($args); - - /* (1) Création admin */ - $id_created = Repo::request('admin', 'create', $username, $mail, $password); - - /* (2) Gestion erreur */ - if( $id_created === false ) - return [ 'error' => new Error(Err::RepoError) ]; - - /* (3) Renvoi @id_admin */ - return [ 'id_admin' => Repo::request('admin', 'getById', $id_created) ]; - - } - - - - /* (3) Updates an existing administrator - * - * @id_admin UID de l'administrateur - * @mail [OPT] Adresse mail de l'administrateur - * @password [OPT] Mot de passe de l'administrateur - * - * @return admin The new administrator data - * - ---------------------------------------------------------*/ - public static function put($args){ - //helps the static analysis - $mail = null; - $password = null; - $id_admin = 0; - extract($args); - - /* (1) If @mail given - ---------------------------------------------------------*/ - if( !is_null($mail) ){ - - /* (1) Update mail address */ - $updated = Repo::request('admin', 'setMail', $id_admin, $mail); - - /* (2) Gestion erreur */ - if( $updated === false ) - return [ 'error' => new Error(Err::RepoError) ]; - - } - - /* (2) If @password given - ---------------------------------------------------------*/ - if( !is_null($password) ){ - - /* (1) Update password */ - $updated = Repo::request('admin', 'setPassword', $id_admin, $password); - - /* (2) Gestion erreur */ - if( $updated === false ) - return [ 'error' => new Error(Err::RepoError) ]; - - } - - /* (3) Renvoi @id_admin */ - return [ 'id_admin' => Repo::request('admin', 'getById', $id_admin) ]; - - } - - - - /* (4) Deletes an existing administrator - * - * @id_admin UID de l'administrateur - * - * @return removed Whether the admin has been removed - * - ---------------------------------------------------------*/ - public static function delete($args){ - $id_admin = 0; - extract($args); - - /* (1) Dispatch du status */ - return [ 'removed' => Repo::request('admin', 'delete', $id_admin) ]; - - } - - } diff --git a/build/database/core/Repo.php b/build/database/core/Repo.php index d591b3d..6a09828 100644 --- a/build/database/core/Repo.php +++ b/build/database/core/Repo.php @@ -26,7 +26,7 @@ - public static function request(String $repo=null, String $method=null){ + public static function getRepo(String $repo=null) : Repo_i{ /* (1) Check arguments ---------------------------------------------------------*/ @@ -34,11 +34,7 @@ if( !is_string($repo) || strlen($repo) < 1 ) throw new \Exception("@repo is not a non-empty string"); - /* (2) Check @method */ - if( !is_string($method) || strlen($method) < 1 ) - throw new \Exception("@method is not a non-empty string"); - - /* (3) Check class path */ + /* (1) Check class path */ $class_path = "\\database\\repo\\$repo"; if( !\class_exists($class_path) ) @@ -58,19 +54,7 @@ \call_user_func([$instance, 'setPDO'], self::$driver->pdo()); - /* (3) Check if the method exists */ - if( !\method_exists($instance, $method) ) - throw new \Exception("Repo '$repo' has no public method '$method'"); - - /* (4) Fetch response (send arguments as well) */ - $response = call_user_func_array([$instance, $method], array_slice(func_get_args(), 2)); - - /* (5) Call post-script */ - $instance = null; - - /* (6) Dispatch response */ - return $response; - + return $instance; } diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index f5aecfa..3d3e535 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -89,9 +89,9 @@ class professor extends Repo_i { public function getVH(int $id) : array{ $st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, Cat.idCategorie idCat, Prof.hoursToDo du FROM Professeur Prof, Categorie Cat, - (SELECT SUM(C.volume) VHCours , Prof.idProfesseur idProf FROM Cours C, Professeur Prof WHERE C.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHCours, - (SELECT SUM(T.volume) VHTd , Prof.idProfesseur idProf FROM TD T, Professeur Prof WHERE T.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHTd, - (SELECT SUM(T2.volume) VHTp, Prof.idProfesseur idProf FROM TP T2 , Professeur Prof WHERE T2.Professeur_idProfesseur = Prof.idProfesseur GROUP BY Prof.idProfesseur) VHTp + (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 diff --git a/config/modules.json b/config/modules.json index c0901a1..45a9abb 100644 --- a/config/modules.json +++ b/config/modules.json @@ -7,46 +7,6 @@ } }, - "admin": { - - "POST": { - "des": "Creates a new administrator", - "per": [["admin"]], - "par": { - "username": { "des": "The new administrator username", "typ": "varchar(3,20,alphanumeric)" }, - "mail": { "des": "The new administrator email address", "typ": "mail" }, - "password": { "des": "The new administrator passowrd", "typ": "text" } - } - }, - - "PUT": { - "des": "Updates an existing administrator's data", - "per": [["admin"]], - "par": { - "URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "ren": "id_admin" }, - "mail": { "des": "The new administrator email address", "typ": "mail", "opt": true }, - "password": { "des": "The new administrator passowrd", "typ": "text", "opt": true } - } - }, - - "DELETE": { - "des": "Deletes an administrator", - "per": [["admin"]], - "par": { - "URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "opt": true, "ren": "id_admin" } - } - }, - - "GET": { - "des": "Gets an administrator | Gets all administrators if no id defined", - "per": [["admin"]], - "par": { - "URL0": { "des": "The UID of the wanted administrator.", "typ": "id", "opt": true, "ren": "id_admin" } - } - } - - }, - "release": { "GET": { @@ -82,6 +42,16 @@ } }, + "Formation": { + "GET":{ + "des": "Get all data about a formation", + "per": [], + "par": { + "URL0":{"des" : "Id of the formation", "typ": "id", "ren": "idForm", "opt" : false} + } + } + }, + "a": { "b": {