From 6c78d636347efa09607c8efa87165ba7e0ae0134 Mon Sep 17 00:00:00 2001 From: Sofiane Lasri <alasri250@gmail.com> Date: Sat, 22 Oct 2022 22:26:28 +0200 Subject: [PATCH] Reformatage. --- TP4/ex1/app/helpers/views.php | 1 + TP4/ex1/app/models/View.php | 5 +++++ TP4/ex1/controller/ControleurAdherent.php | 14 ++++++++++++-- TP4/ex1/controller/ControleurAuteur.php | 15 +++++++++++++-- TP4/ex1/index.php | 8 ++++---- TP4/ex1/models/Adherent.php | 10 ++++++++++ 6 files changed, 45 insertions(+), 8 deletions(-) diff --git a/TP4/ex1/app/helpers/views.php b/TP4/ex1/app/helpers/views.php index b284f36..2546cdb 100644 --- a/TP4/ex1/app/helpers/views.php +++ b/TP4/ex1/app/helpers/views.php @@ -1,6 +1,7 @@ <?php require_once("app/models/View.php"); /** + * Charge le contenu d'une vue avec des paramètres. * @param string $viewName * @param array $args * @return string diff --git a/TP4/ex1/app/models/View.php b/TP4/ex1/app/models/View.php index 2d8f770..215012d 100644 --- a/TP4/ex1/app/models/View.php +++ b/TP4/ex1/app/models/View.php @@ -83,6 +83,11 @@ class View return $viewContent; } + /** + * @param string $viewCode + * @param array $args + * @return string + */ public static function render(string $viewCode, array $args = []): string { extract($args); diff --git a/TP4/ex1/controller/ControleurAdherent.php b/TP4/ex1/controller/ControleurAdherent.php index b4900c6..3b12d30 100644 --- a/TP4/ex1/controller/ControleurAdherent.php +++ b/TP4/ex1/controller/ControleurAdherent.php @@ -3,13 +3,23 @@ require_once("models/Adherent.php"); class ControleurAdherent { - public static function lireAdherents() + /** + * Charge la page de la liste des adhérents. + * @return string + * @throws Exception + */ + public static function lireAdherents(): string { $adherents = Adherent::getAllAdherents(); return view('adherents.les-adherents', ['adherents' => $adherents]); } - public static function lireAdherent() + /** + * Charge la page du détail d'un adhérent. + * @return string + * @throws Exception + */ + public static function lireAdherent(): string { if (empty($_GET["login"])) { die("Le paramètre login n'est pas spécifié."); diff --git a/TP4/ex1/controller/ControleurAuteur.php b/TP4/ex1/controller/ControleurAuteur.php index 9a80bab..08a476c 100644 --- a/TP4/ex1/controller/ControleurAuteur.php +++ b/TP4/ex1/controller/ControleurAuteur.php @@ -1,15 +1,26 @@ <?php require_once("models/Auteur.php"); +/** + * + */ class ControleurAuteur { - public static function lireAuteurs() + /** + * Charge la page de la liste des auteurs. + * @return string + */ + public static function lireAuteurs() : string { $auteurs = Auteur::getAllAuteurs(); return view('auteurs.les-auteurs', ['auteurs' => $auteurs]); } - public static function lireAuteur() + /** + * Charge la page du détail d'un auteur. + * @return string + */ + public static function lireAuteur() : string { if (empty($_GET["numAuteur"])) { die("Le paramètre numAuteur n'est pas spécifié."); diff --git a/TP4/ex1/index.php b/TP4/ex1/index.php index 3bf1b9c..9c113ff 100644 --- a/TP4/ex1/index.php +++ b/TP4/ex1/index.php @@ -12,13 +12,13 @@ require_once("controller/ControleurAdherent.php"); Database::connect(); -if(empty($_GET["action"])){ +if (empty($_GET["action"])) { echo ControleurAuteur::lireAuteurs(); -}else{ - if(in_array($_GET["action"], get_class_methods('ControleurAuteur'))){ +} else { + if (in_array($_GET["action"], get_class_methods('ControleurAuteur'))) { $action = $_GET["action"]; echo ControleurAuteur::$action(); - }elseif(in_array($_GET["action"], get_class_methods('ControleurAdherent'))){ + } elseif (in_array($_GET["action"], get_class_methods('ControleurAdherent'))) { $action = $_GET["action"]; echo ControleurAdherent::$action(); } diff --git a/TP4/ex1/models/Adherent.php b/TP4/ex1/models/Adherent.php index 9b09e4c..60de2e8 100644 --- a/TP4/ex1/models/Adherent.php +++ b/TP4/ex1/models/Adherent.php @@ -33,6 +33,10 @@ class Adherent $this->numCategorie = $numCategorie; } + /** + * @return array + * @throws Exception + */ public static function getAllAdherents(): array { // écriture de la requête @@ -56,6 +60,12 @@ class Adherent return $tableau; } + /** + * Trouve un adhérent selon son login unique. + * @param $login + * @return Adherent + * @throws Exception + */ public static function getAdherentByLogin($login) : Adherent { // écriture de la requête -- GitLab