[repo.formation] getProfessors(@form_id)
This commit is contained in:
parent
fec2a504a8
commit
3c97079d25
|
@ -13,37 +13,84 @@ use database\core\Repo_i;
|
|||
|
||||
class formation extends Repo_i {
|
||||
|
||||
public function create(string $label, bool $isInternal) : int{
|
||||
$st = $this->pdo->prepare("INSERT INTO Formation (labelFormation, isInternal) VALUE (:label,:isInternal);");
|
||||
/* (1) Creates a new formation
|
||||
*
|
||||
* @label<String> The formation label
|
||||
* @isInternal<bool> Whether the formation is internal
|
||||
*
|
||||
* @return form_id<int> The formation UID (or NULL on error)
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
public function create(string $label, bool $isInternal) : ?int{
|
||||
|
||||
$st->execute([
|
||||
"label" => $label,
|
||||
"isInternal" => $isInternal? 1 : 0
|
||||
/* (1) Prepare statement */
|
||||
$st = $this->pdo->prepare("INSERT INTO `Formation` (`labelFormation`, `isInternal`) VALUE (:label, :isInternal);");
|
||||
|
||||
/* (2) Bind params and execute statement */
|
||||
if( is_bool($st) ) return NULL;
|
||||
$success = $st->execute([
|
||||
':label' => $label,
|
||||
':isInternal' => $isInternal ? 1 : 0
|
||||
]);
|
||||
|
||||
/* (3) Manage error */
|
||||
if( !$success )
|
||||
return NULL;
|
||||
|
||||
/* (4) Return inserted ID */
|
||||
return $this->pdo->lastInsertId();
|
||||
|
||||
}
|
||||
|
||||
public function exists(string $label) : int{
|
||||
$st = $this->pdo->prepare("SELECT idFormation FROM Formation WHERE labelFormation = :label");
|
||||
|
||||
$st->execute([
|
||||
"label" => $label
|
||||
]);
|
||||
|
||||
return $st->fetch()["idFormation"]?: 0;
|
||||
/* (2) Check if a formation exists (by its label)
|
||||
*
|
||||
* @label<String> The formation label
|
||||
*
|
||||
* @return form_id<int> The formation UID (or NULL on error)
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
public function exists(string $label) : ?int{
|
||||
|
||||
/* (1) Prepare statement */
|
||||
$st = $this->pdo->prepare("SELECT `idFormation` FROM `Formation` WHERE `labelFormation` = :label");
|
||||
|
||||
/* (2) Bind params and execute statement */
|
||||
if( is_bool($st) ) return NULL;
|
||||
$success = $st->execute([ ':label' => $label ]);
|
||||
|
||||
/* (3) Manage error */
|
||||
if( !$success )
|
||||
return NULL;
|
||||
|
||||
/* (4) Return if we have a result */
|
||||
|
||||
return $st->fetch()['idFormation'] ?: 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (3) Deletes a formation
|
||||
*
|
||||
* @return deleted<bool> Whether the formation have been deleeted successfully
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
public function delete(int $id) : bool{
|
||||
$st = $this->pdo->prepare("DELETE FROM Formation WHERE idFormation = :id");
|
||||
|
||||
return $st->execute([
|
||||
"id" => $id
|
||||
]);
|
||||
/* (1) Prepare statement */
|
||||
$st = $this->pdo->prepare("DELETE FROM `Formation` WHERE `idFormation` = :id");
|
||||
|
||||
/* (2) Bind params and execute request */
|
||||
if( is_bool($st) ) return false;
|
||||
|
||||
/* (3) Dispatch the execution status */
|
||||
return $st->execute([ ':id' => $id ]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (x) Gets a formation by its ID || getAll
|
||||
/* (4) Gets a formation by its ID || getAll
|
||||
*
|
||||
* @form_id<int> [OPT] The formation id, if not set, getAll()
|
||||
*
|
||||
|
@ -84,4 +131,44 @@ class formation extends Repo_i {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/* (5) Gets all professors who teaches a formation by ids (array)
|
||||
*
|
||||
* @form_id<int> The formation id
|
||||
*
|
||||
* @return professors<array> The professors' UID matching the @form_id formation
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
public function getProfessors(int $form_id) : array{
|
||||
|
||||
/* (1) Prepare statement */
|
||||
$st = $this->pdo->prepare("SELECT p.idProfesseur
|
||||
FROM Professeur p, Formation f
|
||||
WHERE (
|
||||
p.idProfesseur IN ( SELECT p_cr.idProfesseur FROM Professeur p_cr, UE ue, Cours c WHERE c.Professeur_idProfesseur = p_cr.idProfesseur AND c.UE_code = ue.code AND ue.Formation_idFormation = f.idFormation )
|
||||
OR p.idProfesseur IN ( SELECT p_td.idProfesseur FROM Professeur p_td, UE ue, TD t WHERE t.Professeur_idProfesseur = p_td.idProfesseur AND t.UE_code = ue.code AND ue.Formation_idFormation = f.idFormation )
|
||||
OR p.idProfesseur IN ( SELECT p_tp.idProfesseur FROM Professeur p_tp, UE ue, TP t WHERE t.Professeur_idProfesseur = p_tp.idProfesseur AND t.UE_code = ue.code AND ue.Formation_idFormation = f.idFormation )
|
||||
)
|
||||
AND f.idFormation = :form_id;");
|
||||
|
||||
/* (2) Bind params and execute statement */
|
||||
if( is_bool($st) ) return [];
|
||||
$success = $st->execute([ ':form_id' => $form_id ]);
|
||||
|
||||
/* (3) Manage error */
|
||||
if( !$success )
|
||||
return [];
|
||||
|
||||
/* (4) Get data */
|
||||
$fetched = $st->fetchAll();
|
||||
|
||||
/* (5) Return [] on no result */
|
||||
if( $fetched === false )
|
||||
return [];
|
||||
|
||||
/* (6) Return data */
|
||||
return $fetched;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue