2018-02-27 13:46:38 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: lucas
|
|
|
|
* Date: 20/02/18
|
|
|
|
* Time: 20:31
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace database\repo;
|
|
|
|
|
|
|
|
|
|
|
|
use database\core\Repo_i;
|
|
|
|
|
|
|
|
class professor extends Repo_i {
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
|
|
|
|
/* (1) 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
|
|
|
|
*
|
2018-03-05 17:48:30 +00:00
|
|
|
* @return prof_id<int> The professor's UID (or -1 on error)
|
2018-03-01 16:22:22 +00:00
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-03-13 23:12:18 +00:00
|
|
|
public function create(string $lastName, string $firstName, int $category, int $hoursToDo = 0, ?string $initials = null , bool $isAdmin = false , ?string $casLogin = null ) : ?int{
|
2018-03-01 16:22:22 +00:00
|
|
|
|
|
|
|
/* (1) Prepare Statement */
|
|
|
|
$st = $this->pdo->prepare("INSERT INTO
|
|
|
|
Professeur(`casLogin`, `lastName`, `firstName`, `abreviation`, `admin`, `hoursToDo`, `Categorie_idCategorie`)
|
|
|
|
VALUE (:casLogin, :lastName, :firstName, :abrev, :is_admin, :hoursToDo, :cat);");
|
|
|
|
|
|
|
|
/* (2) Bind params and execute */
|
|
|
|
$success = $st->execute([
|
|
|
|
':casLogin' => $casLogin,
|
|
|
|
':lastName' => $lastName,
|
|
|
|
':firstName' => $firstName,
|
|
|
|
':abrev' => $initials,
|
|
|
|
':is_admin' => $isAdmin ? 1 : 0,
|
|
|
|
':hoursToDo' => $hoursToDo,
|
|
|
|
':cat' => $category
|
2018-02-27 13:46:38 +00:00
|
|
|
]);
|
|
|
|
|
2018-03-13 23:12:18 +00:00
|
|
|
$profId = $this->pdo->lastInsertId();
|
|
|
|
|
|
|
|
/* (3) synchroize the meta database */
|
|
|
|
if(!is_null($casLogin)){
|
|
|
|
$st = $this->pdo->prepare("INSERT IGNORE INTO meta_vhost.casUser(casLogin, firstName, lastName) VALUE (:casLogin,:firstName,:lastName)");
|
|
|
|
$st->execute([
|
|
|
|
"casLogin" => $casLogin,
|
|
|
|
"firstName" => $firstName,
|
|
|
|
"lastName" => $lastName
|
|
|
|
]);
|
|
|
|
|
|
|
|
$st = $this->pdo->prepare("INSERT INTO meta_vhost.linkedDep(departement_iddepartement, casUser_casLogin) VALUE (:idDep,:casLogin)");
|
|
|
|
$st->execute([
|
|
|
|
"idDep" => $_SESSION['CurrentDepartementId'],
|
|
|
|
"casLogin" => $casLogin
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
/* (3) Manage error */
|
|
|
|
if( !$success )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* (4) Return inserted ID */
|
2018-03-13 23:12:18 +00:00
|
|
|
return $profId;
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
|
|
|
|
/* (2) Check if a professor exists (by its names)
|
|
|
|
*
|
|
|
|
* @lastName<String> The professor's lastName
|
|
|
|
* @firstName<String> The professor's firstName
|
|
|
|
*
|
|
|
|
* @return prof_id<int> The professor's UID (or NULL on error)
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-03-11 15:26:04 +00:00
|
|
|
public function exists(string $lastName, string $firstName, ?string $casLogin = null) : ?int{
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-13 10:26:08 +00:00
|
|
|
/* (1) Manage if @casLogin given/ignored */
|
|
|
|
$cond = is_null($casLogin) ? '' : 'OR `casLogin` = :casLogin';
|
|
|
|
$parm = is_null($casLogin) ? [] : [':casLogin' => $casLogin];
|
|
|
|
|
|
|
|
/* (2) Prepare Statement */
|
2018-03-01 16:22:22 +00:00
|
|
|
$st = $this->pdo->prepare("SELECT idProfesseur
|
|
|
|
FROM Professeur
|
2018-03-13 10:26:08 +00:00
|
|
|
WHERE ( firstName = :firstName AND lastName = :lastName )
|
|
|
|
$cond;");
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-13 10:26:08 +00:00
|
|
|
/* (3) Statement eror */
|
|
|
|
if( is_bool($st) )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* (4) Bind params and execute */
|
|
|
|
$params = array_merge([
|
2018-03-01 16:22:22 +00:00
|
|
|
':firstName' => $firstName,
|
|
|
|
':lastName' => $lastName
|
2018-03-13 10:26:08 +00:00
|
|
|
], $parm);
|
2018-03-11 15:26:04 +00:00
|
|
|
|
2018-03-13 10:44:33 +00:00
|
|
|
$success = $st->execute($params);
|
2018-02-27 13:46:38 +00:00
|
|
|
|
2018-03-13 10:26:08 +00:00
|
|
|
/* (5) Return NULL on error */
|
2018-03-01 16:22:22 +00:00
|
|
|
if( !$success )
|
|
|
|
return NULL;
|
|
|
|
|
2018-03-13 10:26:08 +00:00
|
|
|
/* (7) Return @prof_id or NULL if nothing found */
|
2018-03-01 16:22:22 +00:00
|
|
|
return $st->fetch()['idProfesseur'] ?: NULL;
|
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 23:12:18 +00:00
|
|
|
public function getLinkedDepartment(string $casLogin) : ?array{
|
|
|
|
|
|
|
|
/* (1) Prepare Statement */
|
|
|
|
$st = $this->pdo->prepare("SELECT d2.iddepartement idDep, d2.label labelDep, d2.databaseName dbName
|
|
|
|
FROM meta_vhost.casUser
|
|
|
|
JOIN meta_vhost.linkedDep D ON casUser.casLogin = D.casUser_casLogin
|
|
|
|
JOIN meta_vhost.departement d2 ON D.departement_iddepartement = d2.iddepartement
|
|
|
|
WHERE casLogin = :caslogin");
|
|
|
|
|
|
|
|
/* (2) Check if statement error */
|
|
|
|
if( is_bool($st) )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* (3) Bind params and execute statement */
|
|
|
|
$success = $st->execute([ ':caslogin' => $casLogin ]);
|
|
|
|
|
|
|
|
/* (4) Manage error */
|
|
|
|
if( !$success )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* (5) Get data */
|
|
|
|
$fetched = $st->fetchAll();
|
|
|
|
|
|
|
|
/* (6) Return NULL on no result */
|
|
|
|
if( $fetched === false )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* (7) Return data */
|
|
|
|
return $fetched;
|
|
|
|
}
|
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
/* (3) Check if a professor exists (by its names)
|
|
|
|
*
|
|
|
|
* @idProf<int> The professor's UID
|
|
|
|
* @lastName<String> [OPT] The professor's new lastName
|
|
|
|
* @firstName<String> [OPT] The professor's new firstName
|
|
|
|
* @category<int> [OPT] The professor's new category ID
|
|
|
|
* @hoursToDo<int> [OPT] The professor's new number of hours to do
|
|
|
|
* @initials<int> [OPT] The professor's new initials
|
|
|
|
* @isAdmin<bool> [OPT] Whether the professor is an admin
|
|
|
|
* @casLogin<String> [OPT] The professor's new CAS username
|
|
|
|
*
|
|
|
|
* @return updated<bool> Whether the updated have been successful
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public function update(int $id, ?String $lastName, ?String $firstName, ?int $category, ?int $hoursToDo, ?String $initials, ?bool $isAdmin, ?String $casLogin) : bool{
|
|
|
|
|
|
|
|
/* (1) Build request */
|
|
|
|
$build_rq = [];
|
|
|
|
$bind_param = [ ':idProfesseur' => $id ];
|
|
|
|
|
2018-03-07 13:58:01 +00:00
|
|
|
if( !is_null($lastName) ){ $build_rq[] = '`lastName` = :lastName'; $bind_param[':lastName'] = $lastName; }
|
|
|
|
if( !is_null($firstName) ){ $build_rq[] = '`firstName` = :firstName'; $bind_param[':firstName'] = $firstName; }
|
|
|
|
if( !is_null($category) ){ $build_rq[] = '`Categorie_idCategorie` = :category'; $bind_param[':category'] = $category; }
|
|
|
|
if( !is_null($hoursToDo) ){ $build_rq[] = '`hoursToDo` = :hoursToDo'; $bind_param[':hoursToDo'] = $hoursToDo; }
|
|
|
|
if( !is_null($initials) ){ $build_rq[] = '`abreviation` = :initials'; $bind_param[':initials'] = $initials; }
|
|
|
|
if( !is_null($isAdmin) ){ $build_rq[] = '`admin` = :isAdmin'; $bind_param[':isAdmin'] = $isAdmin?1:0; }
|
|
|
|
if( !is_null($casLogin) ){ $build_rq[] = '`casLogin` = :casLogin'; $bind_param[':casLogin'] = $casLogin; }
|
2018-03-01 16:22:22 +00:00
|
|
|
|
|
|
|
/* (2) ERROR if no updated field */
|
|
|
|
if( count($build_rq) <= 0 || count($bind_param) <= 1 )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* (3) Build request */
|
|
|
|
$sql_rq = "UPDATE `Professeur` SET ".implode(', ', $build_rq)." WHERE `idProfesseur` = :idProfesseur";
|
|
|
|
|
|
|
|
/* (4) Prepare statement */
|
|
|
|
$st = $this->pdo->prepare($sql_rq);
|
|
|
|
|
|
|
|
/* (5) Return execution success */
|
2018-03-13 23:12:18 +00:00
|
|
|
$success = $st->execute($bind_param);
|
|
|
|
|
|
|
|
$prof = $this->get($id);
|
|
|
|
if($success && !is_null($prof[0]["casLogin"])){
|
|
|
|
//try to get the user
|
|
|
|
$st = $this->pdo->prepare("SELECT * FROM meta_vhost.casUser WHERE casLogin = :casLogin");
|
|
|
|
$st->execute([
|
|
|
|
"casLogin" => $prof[0]["casLogin"]
|
|
|
|
]);
|
|
|
|
|
|
|
|
//is the user does not already exists, we create it
|
|
|
|
if(!is_array($st->fetch())){
|
|
|
|
$st = $this->pdo->prepare("INSERT INTO meta_vhost.casUser(casLogin, firstName, lastName)
|
|
|
|
VALUE(:casLogin,:firstName,:lastName)");
|
|
|
|
}else{
|
|
|
|
$st = $this->pdo->prepare("UPDATE meta_vhost.casUser SET casLogin = :casLogin,firstName = :firstName, lastName = :lastName ");
|
|
|
|
}
|
|
|
|
$st->execute([
|
|
|
|
"firstName" => $prof[0]["firstName"],
|
|
|
|
"lastName" => $prof[0]["lastName"],
|
|
|
|
"casLogin" => $prof[0]["casLogin"]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $success;
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Return whether a professor is an admin
|
|
|
|
*
|
|
|
|
* @idProf<int> The professor's UID
|
|
|
|
*
|
|
|
|
* @return is_admin<bool> Whether the professor is an admin (FALSE if does not exist)
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-02-27 13:46:38 +00:00
|
|
|
public function isAdmin(int $id) : bool{
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
/* (1) Prepare statement */
|
|
|
|
$st = $this->pdo->prepare("SELECT `admin` FROM `Professeur` WHERE `idProfesseur` = :id AND `admin` = 1");
|
2018-02-27 13:46:38 +00:00
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
/* (2) Bind params and execute statement */
|
|
|
|
$success = $st->execute([ ':id' => $id ]);
|
|
|
|
|
|
|
|
/* (3) FALSE on error */
|
|
|
|
if( !$success )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* (4) Return whether we have a result or not */
|
|
|
|
return $st->fetch() == 1;
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (5) Gets a professor by its UID ||| getAll
|
2018-03-01 16:22:22 +00:00
|
|
|
*
|
2018-03-04 10:58:19 +00:00
|
|
|
* @prof_id<int> [OPT] The professor's UID, if not set, getAll()
|
2018-03-01 16:22:22 +00:00
|
|
|
*
|
2018-03-04 10:58:19 +00:00
|
|
|
* @return teachers<array> The professors matching id (NULL on error)
|
2018-03-01 16:22:22 +00:00
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-03-06 15:15:01 +00:00
|
|
|
public function get(?int $prof_id=null) : array{
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (1) Manage if no id given */
|
|
|
|
$cond = is_null($prof_id) ? '' : ' WHERE `idProfesseur` = :id';
|
|
|
|
$parm = is_null($prof_id) ? [] : [':id' => $prof_id];
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (2) Prepare Statement */
|
2018-03-06 15:15:01 +00:00
|
|
|
$st = $this->pdo->prepare("SELECT * FROM `Professeur`$cond ORDER BY abreviation ASC");
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (3) Bind params and execute statement */
|
2018-03-04 11:05:10 +00:00
|
|
|
if( is_bool($st) ) return [];
|
2018-03-04 10:58:19 +00:00
|
|
|
$success = $st->execute($parm);
|
|
|
|
|
|
|
|
/* (4) Manage error */
|
2018-03-01 16:22:22 +00:00
|
|
|
if( !$success )
|
2018-03-04 10:58:19 +00:00
|
|
|
return [];
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (5) Get data */
|
|
|
|
$fetched = $st->fetchAll();
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (6) Return [] on no result */
|
2018-03-01 16:22:22 +00:00
|
|
|
if( $fetched === false )
|
2018-03-04 10:58:19 +00:00
|
|
|
return [];
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (7) Return data */
|
2018-03-01 16:22:22 +00:00
|
|
|
return $fetched;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-03 13:30:52 +00:00
|
|
|
/* (6) Gets a professor by its CAS login
|
|
|
|
*
|
|
|
|
* @cas_login<String> The professor's CAS login
|
|
|
|
*
|
|
|
|
* @return teacher<array> The professor's data (NULL on error / not found)
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public function getByLogin(String $cas_login) : ?array{
|
|
|
|
|
|
|
|
/* (1) Prepare Statement */
|
|
|
|
$st = $this->pdo->prepare("SELECT * FROM `Professeur` WHERE `casLogin` = :cas_login");
|
|
|
|
|
2018-03-11 16:31:46 +00:00
|
|
|
/* (2) Check if statement error */
|
|
|
|
if( is_bool($st) )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* (3) Bind params and execute statement */
|
2018-03-03 13:30:52 +00:00
|
|
|
$success = $st->execute([ ':cas_login' => $cas_login ]);
|
|
|
|
|
2018-03-11 16:31:46 +00:00
|
|
|
/* (4) Manage error */
|
2018-03-03 13:30:52 +00:00
|
|
|
if( !$success )
|
|
|
|
return NULL;
|
|
|
|
|
2018-03-11 16:31:46 +00:00
|
|
|
/* (5) Get data */
|
2018-03-03 13:30:52 +00:00
|
|
|
$fetched = $st->fetch();
|
|
|
|
|
2018-03-11 16:31:46 +00:00
|
|
|
/* (6) Return NULL on no result */
|
2018-03-03 13:30:52 +00:00
|
|
|
if( $fetched === false )
|
|
|
|
return NULL;
|
|
|
|
|
2018-03-11 16:31:46 +00:00
|
|
|
/* (7) Return data */
|
2018-03-03 13:30:52 +00:00
|
|
|
return $fetched;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (7) Gets a professor by its UID ||| getAll
|
2018-03-01 16:22:22 +00:00
|
|
|
*
|
2018-03-04 10:58:19 +00:00
|
|
|
* @prof_id<int> [OPT] The professor's UID, if not set, getAll()
|
|
|
|
*
|
|
|
|
* @return teachers<array> The professors matching id (NULL on error)
|
2018-03-01 16:22:22 +00:00
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-03-04 10:58:19 +00:00
|
|
|
public function getWithVH(?int $prof_id=null) : array{
|
|
|
|
|
|
|
|
/* (1) Manage if no id given */
|
|
|
|
$cond = is_null($prof_id) ? '' : 'Prof.idProfesseur = :id AND';
|
|
|
|
$parm = is_null($prof_id) ? [] : [':id' => $prof_id];
|
|
|
|
|
|
|
|
/* (2) Prepare Statement */
|
|
|
|
$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,
|
2018-03-06 14:21:48 +00:00
|
|
|
(SELECT IFNULL(SUM(Cours.volume),0) VHCours, Prof.idProfesseur idProf
|
2018-03-06 15:07:15 +00:00
|
|
|
FROM Professeur Prof
|
|
|
|
LEFT JOIN Cours ON Prof.idProfesseur = Cours.Professeur_idProfesseur
|
|
|
|
LEFT JOIN UE U ON Cours.UE_code = U.code
|
|
|
|
GROUP BY Prof.idProfesseur, U.disabled
|
|
|
|
HAVING (U.disabled = 0 OR U.disabled IS NULL)) VHCours,
|
2018-03-06 15:15:01 +00:00
|
|
|
|
2018-03-06 15:07:15 +00:00
|
|
|
(SELECT IFNULL(SUM(TD.volume),0) VHTd , Prof.idProfesseur idProf
|
|
|
|
FROM Professeur Prof
|
|
|
|
LEFT JOIN TD ON TD.Professeur_idProfesseur = Prof.idProfesseur
|
|
|
|
LEFT JOIN UE U2 ON TD.UE_code = U2.code
|
|
|
|
GROUP BY Prof.idProfesseur, U2.disabled
|
|
|
|
HAVING (U2.disabled = 0 OR U2.disabled IS NULL)) VHTd,
|
2018-03-06 15:15:01 +00:00
|
|
|
|
2018-03-06 15:07:15 +00:00
|
|
|
(SELECT IFNULL(SUM(TP.volume),0) VHTp, Prof.idProfesseur idProf
|
|
|
|
FROM Professeur Prof
|
|
|
|
LEFT JOIN TP ON TP.Professeur_idProfesseur = Prof.idProfesseur
|
|
|
|
LEFT JOIN UE U3 ON TP.UE_code = U3.code
|
|
|
|
GROUP BY Prof.idProfesseur, U3.disabled
|
|
|
|
HAVING (U3.disabled = 0 OR U3.disabled IS NULL)) VHTp
|
2018-03-04 10:58:19 +00:00
|
|
|
|
|
|
|
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 */
|
2018-03-04 11:05:10 +00:00
|
|
|
if( is_bool($st) ) return [];
|
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
$success = $st->execute($parm);
|
|
|
|
|
|
|
|
/* (4) Manage error */
|
|
|
|
if( !$success )
|
|
|
|
return [];
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (5) Get data */
|
|
|
|
$fetched = $st->fetchAll();
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-03-04 10:58:19 +00:00
|
|
|
/* (6) Return [] on no result */
|
|
|
|
if( $fetched === false )
|
2018-03-01 16:22:22 +00:00
|
|
|
return [];
|
|
|
|
|
2018-03-06 09:53:02 +00:00
|
|
|
/* (7) Compute additional data */
|
|
|
|
|
|
|
|
foreach ($fetched as &$prof){
|
|
|
|
/* (1) If not in category 1 nor 3 -> equivalentTD = TD + 2/3.TP + 1.5.COURS */
|
|
|
|
if(in_array($prof["idCat"],[1,3])){
|
|
|
|
$prof["equiTD"] = $prof["VHTd"] + $prof["VHTp"] + 1.5*$prof["VHCours"];
|
|
|
|
|
|
|
|
if($prof["equiTD"] > $prof["hoursToDo"]){
|
|
|
|
$partTP = $prof["VHTp"] / $prof["equiTD"];
|
|
|
|
$valReelleTP = $partTP * $prof["hoursToDo"];
|
|
|
|
$prof["equiTD"] = round(1.5*$prof["VHCours"] + $prof["VHTd"] + $valReelleTP + ($prof["VHTp"] - $valReelleTP)*(2/3),2);
|
|
|
|
}
|
|
|
|
|
|
|
|
$prof['VHComp'] = round($prof['equiTD'] - $prof['hoursToDo'], 2);
|
|
|
|
$prof['VHComp'] = ( $prof['VHComp'] < 0 ) ? 0 : $prof['VHComp'];
|
|
|
|
}else{
|
2018-03-08 17:41:52 +00:00
|
|
|
$prof["equiTD"] = $prof["VHTd"] + (2/3)*$prof["VHTp"] + 1.5*$prof["VHCours"];
|
2018-03-06 18:40:57 +00:00
|
|
|
if(is_numeric($prof["hoursToDo"]) and $prof["hoursToDo"] > 0){
|
|
|
|
$prof['VHComp'] = round($prof['equiTD'] - $prof['hoursToDo'], 2);
|
|
|
|
$prof['VHComp'] = ( $prof['VHComp'] < 0 ) ? 0 : $prof['VHComp'];
|
|
|
|
}else{
|
|
|
|
$prof['VHComp'] = 0;
|
|
|
|
}
|
2018-03-06 09:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (8) Return data */
|
2018-03-04 10:58:19 +00:00
|
|
|
return $fetched;
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-03 13:30:52 +00:00
|
|
|
/* (8) Deletes a professor
|
2018-03-01 16:22:22 +00:00
|
|
|
*
|
|
|
|
* @return deleted<bool> Whether the professor have been deleeted successfully
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2018-02-27 13:46:38 +00:00
|
|
|
public function delete(int $id) : bool{
|
|
|
|
|
2018-03-13 23:12:18 +00:00
|
|
|
//we have to store the professor to synchronize the meta database later
|
|
|
|
$prof = $this->get($id);
|
|
|
|
|
2018-03-01 16:22:22 +00:00
|
|
|
/* (1) Prepare statement */
|
|
|
|
$st = $this->pdo->prepare("DELETE FROM `Professeur` WHERE `idProfesseur` = :id");
|
|
|
|
|
|
|
|
/* (2) Return the execution status */
|
2018-03-13 23:12:18 +00:00
|
|
|
$success = $st->execute([ ':id' => $id ]);
|
|
|
|
|
|
|
|
if($success){
|
|
|
|
//delete the association
|
|
|
|
$st = $this->pdo->prepare("DELETE FROM meta_vhost.linkedDep WHERE casUser_casLogin = :casLogin AND departement_iddepartement = :idDep");
|
|
|
|
$st->execute([
|
|
|
|
"casLogin" => $prof[0]["casLogin"],
|
|
|
|
"idDep" => $_SESSION['CurrentDepartementId']
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $success;
|
2018-03-01 16:22:22 +00:00
|
|
|
|
2018-02-27 13:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|