From e153b7ecb410bc0ecc63560a0f9c4bf4ba7834d0 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 21 Mar 2018 14:42:52 +0100 Subject: [PATCH] [repo.cours] getForProfessor [repo.td] getForProfessor [repo.tp] getForProfessor --- build/database/repo/cours.php | 47 ++++++++++++++++++++++++++++++++++- build/database/repo/td.php | 45 +++++++++++++++++++++++++++++++++ build/database/repo/tp.php | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 1 deletion(-) diff --git a/build/database/repo/cours.php b/build/database/repo/cours.php index 509b115..51e08f7 100644 --- a/build/database/repo/cours.php +++ b/build/database/repo/cours.php @@ -201,7 +201,7 @@ class cours extends Repo_i { } - /* (x) Get groups for a specific UE + /* (6) Get groups for a specific UE * * @code UE code * @@ -246,4 +246,49 @@ class cours extends Repo_i { } + + + /* (7) Get groups for a specific Professor + * + * @prof_id Professor ID + * + * @return groups The list of groups for this Professor + * NULL on error + * + ---------------------------------------------------------*/ + public function getForProfessor(int $prof_id) : ?array{ + + /* (1) Prepare statement */ + $st = $this->pdo->prepare("SELECT + c.UE_code code, + ue.label label, + c.idCours, + IFNULL(lform.flist, '[]') formations, + c.volume + FROM Cours c + LEFT JOIN ( SELECT gc.Cours_idCours idCours, CONCAT('[', GROUP_CONCAT(DISTINCT gc.Formation_idFormation),']') flist + FROM GroupeCours gc + GROUP BY gc.Cours_idCours + ORDER BY gc.Formation_idFormation DESC + ) lform ON c.idCours = lform.idCours + JOIN UE ue ON ue.code = c.UE_code + WHERE c.Professeur_idProfesseur = :prof_id;"); + + /* (2) Check statement */ + if( is_bool($st) ) + return NULL; + + /* (3) Execute statement */ + $success = $st->execute([':prof_id' => $prof_id]); + + /* (4) Check error */ + if( !$success ) + return NULL; + + /* (5) Dispatch fetch result */ + return $st->fetchAll(); + + + } + } \ No newline at end of file diff --git a/build/database/repo/td.php b/build/database/repo/td.php index 2d8a086..e98348c 100644 --- a/build/database/repo/td.php +++ b/build/database/repo/td.php @@ -246,4 +246,49 @@ class td extends Repo_i { } + + + /* (7) Get groups for a specific Professor + * + * @prof_id Professor ID + * + * @return groups The list of groups for this Professor + * NULL on error + * + ---------------------------------------------------------*/ + public function getForProfessor(int $prof_id) : ?array{ + + /* (1) Prepare statement */ + $st = $this->pdo->prepare("SELECT + td.UE_code code, + ue.label label, + td.idTD, + IFNULL(lform.flist, '[]') formations, + td.volume + FROM TD td + LEFT JOIN ( SELECT gtd.TD_idTD idTD, CONCAT('[', GROUP_CONCAT(DISTINCT gtd.Formation_idFormation),']') flist + FROM GroupeTD gtd + GROUP BY gtd.TD_idTD + ORDER BY gtd.Formation_idFormation DESC + ) lform ON td.idTD = lform.idTD + JOIN UE ue ON ue.code = td.UE_code + WHERE td.Professeur_idProfesseur = :prof_id;"); + + /* (2) Check statement */ + if( is_bool($st) ) + return NULL; + + /* (3) Execute statement */ + $success = $st->execute([':prof_id' => $prof_id]); + + /* (4) Check error */ + if( !$success ) + return NULL; + + /* (5) Dispatch fetch result */ + return $st->fetchAll(); + + + } + } \ No newline at end of file diff --git a/build/database/repo/tp.php b/build/database/repo/tp.php index 659434f..8e592f5 100644 --- a/build/database/repo/tp.php +++ b/build/database/repo/tp.php @@ -246,4 +246,49 @@ class tp extends Repo_i { } + + + /* (7) Get groups for a specific Professor + * + * @prof_id Professor ID + * + * @return groups The list of groups for this Professor + * NULL on error + * + ---------------------------------------------------------*/ + public function getForProfessor(int $prof_id) : ?array{ + + /* (1) Prepare statement */ + $st = $this->pdo->prepare("SELECT + tp.UE_code code, + ue.label label, + tp.idTP, + IFNULL(lform.flist, '[]') formations, + tp.volume + FROM TP tp + LEFT JOIN ( SELECT gtp.TP_idTP idTP, CONCAT('[', GROUP_CONCAT(DISTINCT gtp.Formation_idFormation),']') flist + FROM GroupeTP gtp + GROUP BY gtp.TP_idTP + ORDER BY gtp.Formation_idFormation DESC + ) lform ON tp.idTP = lform.idTP + JOIN UE ue ON ue.code = tp.UE_code + WHERE tp.Professeur_idProfesseur = :prof_id;"); + + /* (2) Check statement */ + if( is_bool($st) ) + return NULL; + + /* (3) Execute statement */ + $success = $st->execute([':prof_id' => $prof_id]); + + /* (4) Check error */ + if( !$success ) + return NULL; + + /* (5) Dispatch fetch result */ + return $st->fetchAll(); + + + } + } \ No newline at end of file