2018-03-01 14:57:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: lucas
|
|
|
|
* Date: 27/02/18
|
2018-03-01 16:21:48 +00:00
|
|
|
* Time: 16:19
|
2018-03-01 14:57:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace api\module;
|
|
|
|
|
|
|
|
|
|
|
|
use database\core\Repo;
|
2018-03-01 16:21:48 +00:00
|
|
|
use database\repo\professor;
|
2018-03-01 16:45:40 +00:00
|
|
|
use error\core\Error;
|
|
|
|
use error\core\Err;
|
2018-03-01 14:57:25 +00:00
|
|
|
|
2018-03-02 08:27:58 +00:00
|
|
|
class professorController{
|
2018-03-01 14:57:25 +00:00
|
|
|
|
2018-03-01 16:31:15 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
private static function proccess_vh(array &$vh_prof){
|
|
|
|
|
|
|
|
/* (1) If not in category 1 nor 3 -> equivalentTD = TD + 2/3.TP + 1.5.COURS */
|
2018-03-05 18:42:37 +00:00
|
|
|
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'] );
|
2018-03-04 10:58:19 +00:00
|
|
|
// 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 */
|
2018-03-05 18:42:37 +00:00
|
|
|
if($vh_prof['equiTD'] > $vh_prof['hoursToDo']){
|
2018-03-04 10:58:19 +00:00
|
|
|
|
|
|
|
/* (3.1) @valTP = HeuresDues.(TP / equivalentTD) */
|
2018-03-05 18:42:37 +00:00
|
|
|
$valTP = $vh_prof['hoursToDo'] * ( $vh_prof['VHTp'] / $vh_prof['equiTD'] );
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (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 */
|
2018-03-05 18:42:37 +00:00
|
|
|
$vh_prof['VHComp'] = round($vh_prof['equiTD'] - $vh_prof['hoursToDo'], 2);
|
2018-03-04 10:58:19 +00:00
|
|
|
$vh_prof['VHComp'] = ( $vh_prof['VHComp'] < 0 ) ? 0 : $vh_prof['VHComp'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-01 16:31:15 +00:00
|
|
|
/* (1) Returns 1 or all professors
|
|
|
|
*
|
|
|
|
* @prof_id<int> [OPT] The professor UID
|
|
|
|
*
|
|
|
|
* @return professors<array> The professor(s) data
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-03-01 14:57:25 +00:00
|
|
|
public static function get($args){
|
2018-03-01 16:21:48 +00:00
|
|
|
$prof_id = null;
|
2018-03-05 18:42:37 +00:00
|
|
|
$with_vh = 0;
|
2018-03-01 14:57:25 +00:00
|
|
|
extract($args);
|
|
|
|
|
2018-03-01 16:31:15 +00:00
|
|
|
/* Get the professor repo */
|
2018-03-01 16:45:40 +00:00
|
|
|
/** @var professor $prof_repo */
|
2018-03-01 16:31:15 +00:00
|
|
|
$prof_repo = Repo::getRepo('professor');
|
|
|
|
|
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (1) If with VH data
|
2018-03-01 16:31:15 +00:00
|
|
|
---------------------------------------------------------*/
|
2018-03-05 18:42:37 +00:00
|
|
|
if( is_int($with_vh) && $with_vh === 1 ){
|
2018-03-01 16:31:15 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (1) Get All professors or 1 by its id (if set) */
|
|
|
|
$fetched = $prof_repo->getWithVH($prof_id);
|
2018-03-01 16:31:15 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (2) Process VH */
|
|
|
|
foreach($fetched as &$vh_prof)
|
|
|
|
self::proccess_vh($vh_prof);
|
2018-03-01 16:31:15 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (3) Return data */
|
|
|
|
return ['professors' => $fetched];
|
2018-03-01 16:31:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (2) If without VH data (only Professor.*)
|
2018-03-01 16:31:15 +00:00
|
|
|
---------------------------------------------------------*/
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (1) Get All professors or 1 by its id (if set) */
|
|
|
|
$fetched = $prof_repo->get($prof_id);
|
|
|
|
|
|
|
|
/* (3) Return data */
|
|
|
|
return ['professors' => $fetched];
|
2018-03-01 16:45:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Creates a new professor
|
|
|
|
*
|
|
|
|
* @lastName<String> The professor's lastName
|
|
|
|
* @firstName<String> The professor's firstName
|
|
|
|
* @category<int> The professor's category ID
|
|
|
|
* @hoursToDo<int> The professor's number of hours to do
|
|
|
|
* @initials<int> The professor's initials
|
|
|
|
* @isAdmin<bool> Whether the professor is an admin
|
|
|
|
* @casLogin<String> The professor's CAS username
|
|
|
|
*
|
|
|
|
* @return prof_id<int> The created professor UID (if no error)
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public static function post($args){
|
|
|
|
$lastName = "";
|
|
|
|
$firstName = "";
|
|
|
|
$category = 0;
|
|
|
|
$hoursToDo = 0;
|
|
|
|
$initials = "";
|
|
|
|
$isAdmin = false;
|
2018-03-01 17:07:32 +00:00
|
|
|
$casLogin = null;
|
2018-03-01 16:45:40 +00:00
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* Get the professor repo */
|
|
|
|
/** @var professor $prof_repo */
|
|
|
|
$prof_repo = Repo::getRepo('professor');
|
|
|
|
|
2018-03-01 17:01:45 +00:00
|
|
|
/* (1) Check if professor already exists */
|
|
|
|
$exists = $prof_repo->exists($lastName, $firstName);
|
2018-03-01 16:45:40 +00:00
|
|
|
|
2018-03-01 17:01:45 +00:00
|
|
|
/* (2) If found -> already exists */
|
|
|
|
if( !is_null($exists) )
|
|
|
|
return ['error' => new Error(Err::AlreadyExists)];
|
|
|
|
|
|
|
|
/* (3) Else try to create */
|
2018-03-01 16:45:40 +00:00
|
|
|
$repo_rtn = $prof_repo->create(
|
|
|
|
$lastName,
|
|
|
|
$firstName,
|
|
|
|
$category,
|
|
|
|
$hoursToDo,
|
|
|
|
$initials,
|
|
|
|
$isAdmin,
|
2018-03-01 17:01:45 +00:00
|
|
|
is_null($casLogin) ? "" : $casLogin
|
2018-03-01 16:45:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2018-03-01 17:01:45 +00:00
|
|
|
/* (4) If repo error -> return it */
|
2018-03-01 16:45:40 +00:00
|
|
|
if( is_null($repo_rtn) )
|
|
|
|
return ['error' => new Error(Err::RepoError)];
|
|
|
|
|
2018-03-01 17:01:45 +00:00
|
|
|
|
|
|
|
/* (5) Else return UID */
|
2018-03-01 16:45:40 +00:00
|
|
|
return ['created_uid' => $repo_rtn];
|
|
|
|
|
2018-03-01 14:57:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 17:07:32 +00:00
|
|
|
|
|
|
|
/* (3) Deletes an existing professor
|
|
|
|
*
|
|
|
|
* @prof_id<int> The professor UID
|
|
|
|
*
|
|
|
|
* @return deleted<bool> Whether it has been removed
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public static function delete($args){
|
|
|
|
$prof_id = 0;
|
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* Get the professor repo */
|
|
|
|
/** @var professor $prof_repo */
|
|
|
|
$prof_repo = Repo::getRepo('professor');
|
|
|
|
|
|
|
|
/* (1) Try to delete */
|
|
|
|
return ['deleted' => $prof_repo->delete($prof_id)];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-01 17:25:21 +00:00
|
|
|
|
|
|
|
/* (4) Edits an existing professor
|
|
|
|
*
|
|
|
|
* @prof_id<int> The professor UID
|
|
|
|
* @lastName<String> [OPT] The professor's lastName
|
|
|
|
* @firstName<String> [OPT] The professor's firstName
|
|
|
|
* @category<int> [OPT] The professor's category ID
|
|
|
|
* @hoursToDo<int> [OPT] The professor's number of hours to do
|
|
|
|
* @initials<int> [OPT] The professor's initials
|
|
|
|
* @isAdmin<bool> [OPT] Whether the professor is an admin
|
|
|
|
* @casLogin<String> [OPT] The professor's CAS username
|
|
|
|
*
|
|
|
|
* @return updated<bool> Whether it has been updated
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public static function put($args){
|
|
|
|
$prof_id = 0;
|
|
|
|
$lastName = null;
|
|
|
|
$firstName = null;
|
|
|
|
$category = null;
|
|
|
|
$hoursToDo = null;
|
|
|
|
$initials = null;
|
|
|
|
$isAdmin = null;
|
|
|
|
$casLogin = null;
|
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* Get the professor repo */
|
|
|
|
/** @var professor $prof_repo */
|
|
|
|
$prof_repo = Repo::getRepo('professor');
|
|
|
|
|
|
|
|
/* (1) Try to update */
|
|
|
|
return ['updated' => $prof_repo->update(
|
|
|
|
$prof_id,
|
|
|
|
$lastName,
|
|
|
|
$firstName,
|
|
|
|
$category,
|
|
|
|
$hoursToDo,
|
|
|
|
$initials,
|
|
|
|
$isAdmin,
|
|
|
|
$casLogin
|
|
|
|
)];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:57:25 +00:00
|
|
|
}
|