diff --git a/TP5/controller/ControleurAdherent.php b/TP5/controller/ControleurAdherent.php index 395bd293ad972e63ca041fb0a4dab6d7298821ce..7b9744640d3fcf8cd9bbfb9970d3e22d7e6fe525 100644 --- a/TP5/controller/ControleurAdherent.php +++ b/TP5/controller/ControleurAdherent.php @@ -4,6 +4,7 @@ require_once("models/Adherent.php"); class ControleurAdherent extends ControleurObjet { + protected static string $object = "Adherent"; /** * Charge la page de la liste des adhérents. * @return string diff --git a/TP5/controller/ControleurAuteur.php b/TP5/controller/ControleurAuteur.php index 93b7bd1681e8c345fd387ecb4397ac1ca8303010..37c589fd808baadbae38b112dcd55ad3b09a311f 100644 --- a/TP5/controller/ControleurAuteur.php +++ b/TP5/controller/ControleurAuteur.php @@ -4,6 +4,7 @@ require_once("models/Auteur.php"); class ControleurAuteur extends ControleurObjet { + protected static string $object = "Auteur"; /** * Charge la page de la liste des auteurs. * @return string diff --git a/TP5/controller/ControleurLivre.php b/TP5/controller/ControleurLivre.php index dfb16330c3b03765b32eea4a036006398b7925bb..0f0f651cfe0285eed9b76e2c007d300f21e3b637 100644 --- a/TP5/controller/ControleurLivre.php +++ b/TP5/controller/ControleurLivre.php @@ -4,6 +4,7 @@ require_once("models/Livre.php"); class ControleurLivre extends ControleurObjet { + protected static string $object = "Livre"; /** * Charge la page de la liste des adhérents. * @return string @@ -40,7 +41,7 @@ class ControleurLivre extends ControleurObjet $livre = Livre::getLivreByNumLivre($_GET["numLivre"]); return view('simple-data', [ - 'pageTitle' => 'Information du libre', + 'pageTitle' => 'Information du livre', 'pageContent' => $livre->afficher() ]); } diff --git a/TP5/controller/ControleurObjet.php b/TP5/controller/ControleurObjet.php index 2ed8809c067b300ba34aa9665bd74fdbe46f47f4..04f34485eedd31828911f013ce59e4c153a7235d 100644 --- a/TP5/controller/ControleurObjet.php +++ b/TP5/controller/ControleurObjet.php @@ -1,6 +1,15 @@ <?php +/** + * Désolé mais le TP5 est une mauvaise idée de bout en bout. + * Je me suis arrêté à l'ex 2 car je ne vois pas comment on pourrait aisément rassembler tous les contrôleurs ici + * étant donné que le contenu diffère légèrement selon les modèles. + */ class ControleurObjet { - + public static function lireObjets() : string + { + $titre = "Listes des " . strtolower(static::$object) . "s"; + return $titre; + } } \ No newline at end of file diff --git a/TP5/index.php b/TP5/index.php index 17c98ca6cbdfef2a3129d2c8c23fb5a85fd9cb08..47a83c39313ce909c611361cece19289f76cdcb4 100644 --- a/TP5/index.php +++ b/TP5/index.php @@ -17,16 +17,41 @@ Database::connect(); if (empty($_GET["action"])) { echo ControleurAuteur::lireAuteurs(); } 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'))) { - $action = $_GET["action"]; - echo ControleurAdherent::$action(); - } elseif (in_array($_GET["action"], get_class_methods('ControleurLivre'))) { - $action = $_GET["action"]; - echo ControleurLivre::$action(); + // Test TP 5 + if ($_GET["action"] === "lireObjets" && !empty($_GET["objet"])) { + switch ($_GET["objet"]){ + case 'Auteur': + echo ControleurAuteur::lireObjets(); + break; + default: + echo ControleurAuteur::lireObjets(); + break; + } } -} + // Fin test TP5 -?> + // C'est plus long que get_class_methods mais c'est moins sujet à problèmes. + switch ($_GET["action"]){ + case "lireAuteur": + echo ControleurAuteur::lireAuteur(); + break; + case "lireAuteurs": + echo ControleurAuteur::lireAuteurs(); + break; + case "lireAdherent": + echo ControleurAdherent::lireAdherent(); + break; + case "lireAdherents": + echo ControleurAdherent::lireAdherents(); + break; + case "lireLivre": + echo ControleurLivre::lireLivre(); + break; + case "lireLivres": + echo ControleurLivre::lireLivres(); + break; + default: + echo ControleurAuteur::lireAuteur(); + break; + } +}