[repo.professor] get (gets by id if given, else getAll) | getWithVH (same as 'get' but with VH data)
This commit is contained in:
parent
e83b20e9ff
commit
587884d437
|
@ -17,6 +17,33 @@ use error\core\Err;
|
||||||
class professorController{
|
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
|
/* (1) Returns 1 or all professors
|
||||||
*
|
*
|
||||||
* @prof_id<int> [OPT] The professor UID
|
* @prof_id<int> [OPT] The professor UID
|
||||||
|
@ -26,6 +53,7 @@ class professorController{
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
public static function get($args){
|
public static function get($args){
|
||||||
$prof_id = null;
|
$prof_id = null;
|
||||||
|
$with_vh = null;
|
||||||
extract($args);
|
extract($args);
|
||||||
|
|
||||||
/* Get the professor repo */
|
/* Get the professor repo */
|
||||||
|
@ -33,26 +61,30 @@ class professorController{
|
||||||
$prof_repo = Repo::getRepo('professor');
|
$prof_repo = Repo::getRepo('professor');
|
||||||
|
|
||||||
|
|
||||||
/* (1) If @prof_id is set -> getById()
|
/* (1) If with VH data
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
if( !is_null($prof_id) ){
|
if( is_string($with_vh) && $with_vh == '1' ){
|
||||||
|
|
||||||
/* (1) Only get one professor by its id */
|
/* (1) Get All professors or 1 by its id (if set) */
|
||||||
$fetch_prof = $prof_repo->getById((int) $prof_id);
|
$fetched = $prof_repo->getWithVH($prof_id);
|
||||||
|
|
||||||
/* (2) If nothing found -> return empty set */
|
/* (2) Process VH */
|
||||||
if( is_null($fetch_prof) )
|
foreach($fetched as &$vh_prof)
|
||||||
return ['professors' => []];
|
self::proccess_vh($vh_prof);
|
||||||
|
|
||||||
/* (3) Else -> return the professor */
|
/* (3) Return data */
|
||||||
return ['professors' => [$fetch_prof]];
|
return ['professors' => $fetched];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (2) Else -> getAll()
|
/* (2) If without VH data (only Professor.*)
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
return ['professors' => $prof_repo->getAll()];
|
/* (1) Get All professors or 1 by its id (if set) */
|
||||||
|
$fetched = $prof_repo->get($prof_id);
|
||||||
|
|
||||||
|
/* (3) Return data */
|
||||||
|
return ['professors' => $fetched];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,33 +163,37 @@ class professor extends Repo_i {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (5) Gets a professor by its UID
|
/* (5) Gets a professor by its UID ||| getAll
|
||||||
*
|
*
|
||||||
* @idProf<int> The professor's UID
|
* @prof_id<int> [OPT] The professor's UID, if not set, getAll()
|
||||||
*
|
*
|
||||||
* @return teacher<array> The professor's data (NULL on error / not found)
|
* @return teachers<array> The professors matching id (NULL on error)
|
||||||
*
|
*
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
public function getById(int $id) : ?array{
|
public function get(?int $prof_id=null) : ?array{
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Manage if no id given */
|
||||||
$st = $this->pdo->prepare("SELECT * FROM `Professeur` WHERE `idProfesseur` = :id");
|
$cond = is_null($prof_id) ? '' : ' WHERE `idProfesseur` = :id';
|
||||||
|
$parm = is_null($prof_id) ? [] : [':id' => $prof_id];
|
||||||
|
|
||||||
/* (2) Bind params and execute statement */
|
/* (2) Prepare Statement */
|
||||||
$success = $st->execute([ ':id' => $id ]);
|
$st = $this->pdo->prepare("SELECT * FROM `Professeur`$cond GROUP BY abreviation ASC");
|
||||||
|
|
||||||
/* (3) Manage error */
|
/* (3) Bind params and execute statement */
|
||||||
|
$success = $st->execute($parm);
|
||||||
|
|
||||||
|
/* (4) Manage error */
|
||||||
if( !$success )
|
if( !$success )
|
||||||
return NULL;
|
return [];
|
||||||
|
|
||||||
/* (4) Get data */
|
/* (5) Get data */
|
||||||
$fetched = $st->fetch();
|
$fetched = $st->fetchAll();
|
||||||
|
|
||||||
/* (5) Return NULL on no result */
|
/* (6) Return [] on no result */
|
||||||
if( $fetched === false )
|
if( $fetched === false )
|
||||||
return NULL;
|
return [];
|
||||||
|
|
||||||
/* (6) Return data */
|
/* (7) Return data */
|
||||||
return $fetched;
|
return $fetched;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -231,22 +235,57 @@ class professor extends Repo_i {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (7) Gets all professors
|
/* (7) Gets a professor by its UID ||| getAll
|
||||||
*
|
*
|
||||||
* @return teachers<array> The professors' data ([] on error)
|
* @prof_id<int> [OPT] The professor's UID, if not set, getAll()
|
||||||
|
*
|
||||||
|
* @return teachers<array> The professors matching id (NULL on error)
|
||||||
*
|
*
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
public function getAll() : array{
|
public function getWithVH(?int $prof_id=null) : array{
|
||||||
|
|
||||||
/* (1) Set query */
|
/* (1) Manage if no id given */
|
||||||
$query = $this->pdo->query("SELECT * FROM `Professeur` ORDER BY `abreviation` ASC");
|
$cond = is_null($prof_id) ? '' : 'Prof.idProfesseur = :id AND';
|
||||||
|
$parm = is_null($prof_id) ? [] : [':id' => $prof_id];
|
||||||
|
|
||||||
/* (2) If error return empty array */
|
/* (2) Prepare Statement */
|
||||||
if( $query === false )
|
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
|
$st = $this->pdo->prepare("SELECT
|
||||||
|
Prof.idProfesseur, Prof.firstName, Prof.lastName, Prof.casLogin, Prof.abreviation, Prof.admin, Prof.hoursToDo,
|
||||||
|
VHCours, VHTd, VHTp,
|
||||||
|
Cat.idCategorie idCat,
|
||||||
|
Cat.labelCategorie categorie
|
||||||
|
|
||||||
|
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 $cond Prof.Categorie_idCategorie = Cat.idCategorie
|
||||||
|
AND VHCours.idProf = Prof.idProfesseur
|
||||||
|
AND VHTp.idProf = Prof.idProfesseur
|
||||||
|
AND VHTd.idProf = Prof.idProfesseur
|
||||||
|
GROUP BY
|
||||||
|
Prof.idProfesseur;");
|
||||||
|
|
||||||
|
/* (3) Bind params and execute statement */
|
||||||
|
$success = $st->execute($parm);
|
||||||
|
|
||||||
|
/* (4) Manage error */
|
||||||
|
if( !$success )
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
/* (3) Return fetched data */
|
/* (5) Get data */
|
||||||
return $query->fetchAll();
|
$fetched = $st->fetchAll();
|
||||||
|
|
||||||
|
/* (6) Return [] on no result */
|
||||||
|
if( $fetched === false )
|
||||||
|
return [];
|
||||||
|
|
||||||
|
/* (7) Return data */
|
||||||
|
return $fetched;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,16 +319,16 @@ class professor extends Repo_i {
|
||||||
|
|
||||||
/* (1) Prepare Statement */
|
/* (1) Prepare Statement */
|
||||||
$st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, Cat.idCategorie idCat, Prof.hoursToDo du
|
$st = $this->pdo->prepare("SELECT VHCours, VHTd, VHTp, Cat.idCategorie idCat, Prof.hoursToDo du
|
||||||
FROM Professeur Prof, Categorie Cat,
|
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(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(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
|
(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
|
WHERE
|
||||||
Prof.idProfesseur = :idProf AND
|
Prof.idProfesseur = :idProf AND
|
||||||
Prof.Categorie_idCategorie = Cat.idCategorie AND
|
Prof.Categorie_idCategorie = Cat.idCategorie AND
|
||||||
VHCours.idProf = Prof.idProfesseur AND
|
VHCours.idProf = Prof.idProfesseur AND
|
||||||
VHTp.idProf = Prof.idProfesseur AND
|
VHTp.idProf = Prof.idProfesseur AND
|
||||||
VHTd.idProf = Prof.idProfesseur;");
|
VHTd.idProf = Prof.idProfesseur;");
|
||||||
|
|
||||||
/* (2) Bind params and execute */
|
/* (2) Bind params and execute */
|
||||||
$success = $st->execute([ ':idProf' => $id ]);
|
$success = $st->execute([ ':idProf' => $id ]);
|
||||||
|
|
|
@ -82,7 +82,8 @@
|
||||||
"des": "Get one or all professors",
|
"des": "Get one or all professors",
|
||||||
"per": [],
|
"per": [],
|
||||||
"par": {
|
"par": {
|
||||||
"URL0": { "des": "Optional professor UID.", "typ": "id", "ren": "prof_id", "opt": true }
|
"URL0": { "des": "Whether to return VH", "typ": "id", "ren": "with_vh" },
|
||||||
|
"URL1": { "des": "Optional professor UID.", "typ": "id", "ren": "prof_id", "opt": true }
|
||||||
},
|
},
|
||||||
"out": {
|
"out": {
|
||||||
"professors": { "des": "Teacher list", "typ": "array" }
|
"professors": { "des": "Teacher list", "typ": "array" }
|
||||||
|
|
Loading…
Reference in New Issue