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 * * @prof_id [OPT] The professor UID * * @return professors The professor(s) data * ---------------------------------------------------------*/ public static function get($args){ $prof_id = null; $with_vh = ''; extract($args); /* Get the professor repo */ /** @var professor $prof_repo */ $prof_repo = Repo::getRepo('professor'); /* (1) If with VH data ---------------------------------------------------------*/ if( is_string($with_vh) && $with_vh == '1' ){ /* (1) Get All professors or 1 by its id (if set) */ $fetched = $prof_repo->getWithVH($prof_id); /* (2) Process VH */ foreach($fetched as &$vh_prof) self::proccess_vh($vh_prof); /* (3) Return data */ return ['professors' => $fetched]; } /* (2) If without VH data (only Professor.*) ---------------------------------------------------------*/ /* (1) Get All professors or 1 by its id (if set) */ $fetched = $prof_repo->get($prof_id); /* (3) Return data */ return ['professors' => $fetched]; } /* (2) Creates a new professor * * @lastName The professor's lastName * @firstName The professor's firstName * @category The professor's category ID * @hoursToDo The professor's number of hours to do * @initials The professor's initials * @isAdmin Whether the professor is an admin * @casLogin The professor's CAS username * * @return prof_id The created professor UID (if no error) * ---------------------------------------------------------*/ public static function post($args){ $lastName = ""; $firstName = ""; $category = 0; $hoursToDo = 0; $initials = ""; $isAdmin = false; $casLogin = null; extract($args); /* Get the professor repo */ /** @var professor $prof_repo */ $prof_repo = Repo::getRepo('professor'); /* (1) Check if professor already exists */ $exists = $prof_repo->exists($lastName, $firstName); /* (2) If found -> already exists */ if( !is_null($exists) ) return ['error' => new Error(Err::AlreadyExists)]; /* (3) Else try to create */ $repo_rtn = $prof_repo->create( $lastName, $firstName, $category, $hoursToDo, $initials, $isAdmin, is_null($casLogin) ? "" : $casLogin ); /* (4) If repo error -> return it */ if( is_null($repo_rtn) ) return ['error' => new Error(Err::RepoError)]; /* (5) Else return UID */ return ['created_uid' => $repo_rtn]; } /* (3) Deletes an existing professor * * @prof_id The professor UID * * @return deleted 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)]; } /* (4) Edits an existing professor * * @prof_id The professor UID * @lastName [OPT] The professor's lastName * @firstName [OPT] The professor's firstName * @category [OPT] The professor's category ID * @hoursToDo [OPT] The professor's number of hours to do * @initials [OPT] The professor's initials * @isAdmin [OPT] Whether the professor is an admin * @casLogin [OPT] The professor's CAS username * * @return updated 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 )]; } }