Merge branch 'master' of https://git.xdrm.io/ptut/vhost
This commit is contained in:
commit
9cb6b429c4
|
@ -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;
|
||||
|
@ -72,7 +78,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);
|
||||
|
@ -246,74 +260,95 @@ 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){
|
||||
$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"];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return [ 'data' => ["professors" => $allProf, "formations" => $allFormations, "UEs" => $allUE ] ];
|
||||
}catch (Exception $e){
|
||||
return [ 'error' => new Error(Err::UnknownError) ];
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: lucas
|
||||
* Date: 27/02/18
|
||||
* Time: 16:19
|
||||
*/
|
||||
|
||||
namespace api\module\Professor;
|
||||
|
||||
|
||||
use database\core\Repo;
|
||||
use database\repo\professor;
|
||||
|
||||
class Stats
|
||||
{
|
||||
public static function get($args){
|
||||
$idProf = 0;
|
||||
extract($args);
|
||||
|
||||
//get data from the database
|
||||
|
||||
/** @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"];
|
||||
}
|
||||
|
||||
return ["data" => $VH];
|
||||
}
|
||||
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace api\module;
|
||||
|
||||
use \error\core\Error;
|
||||
use \error\core\Err;
|
||||
use \database\core\Repo;
|
||||
|
||||
|
||||
class admin{
|
||||
|
||||
|
||||
/* (1) Return an admin data
|
||||
*
|
||||
* @id_admin<id> [OPT] UID de l'administrateur
|
||||
*
|
||||
* @return data<Array> 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<string> Identifiant de l'administrateur
|
||||
* @mail<string> Adresse mail de l'administrateur
|
||||
* @password<string> Mot de passe de l'administrateur
|
||||
*
|
||||
* @return admin<array> 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<id> UID de l'administrateur
|
||||
* @mail<string> [OPT] Adresse mail de l'administrateur
|
||||
* @password<string> [OPT] Mot de passe de l'administrateur
|
||||
*
|
||||
* @return admin<array> 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<id> UID de l'administrateur
|
||||
*
|
||||
* @return removed<bool> 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) ];
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 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;");
|
||||
$st->execute([
|
||||
"idProf" => $id
|
||||
]);
|
||||
|
||||
return $st->fetch();
|
||||
}
|
||||
|
||||
}
|
|
@ -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": {
|
||||
|
@ -70,6 +30,28 @@
|
|||
}
|
||||
},
|
||||
|
||||
"Professor":{
|
||||
"Stats": {
|
||||
"GET":{
|
||||
"des": "Get statistics of the professor",
|
||||
"per": [],
|
||||
"par":{
|
||||
"URL0": {"des" : "Id of the professor", "typ": "id", "ren": "idProf", "opt" : false}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"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": {
|
||||
|
|
Loading…
Reference in New Issue