diff --git a/TP4/ex1/controller/ControleurAdherants.php b/TP4/ex1/controller/ControleurAdherants.php deleted file mode 100644 index c83bf3ee595635054353626ddf9acf482c47365e..0000000000000000000000000000000000000000 --- a/TP4/ex1/controller/ControleurAdherants.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -class ControleurAdherants -{ - -} \ No newline at end of file diff --git a/TP4/ex1/controller/ControleurAdherent.php b/TP4/ex1/controller/ControleurAdherent.php new file mode 100644 index 0000000000000000000000000000000000000000..1cb10daee0aa30255db17f085eb682fb7faa6c5f --- /dev/null +++ b/TP4/ex1/controller/ControleurAdherent.php @@ -0,0 +1,11 @@ +<?php +require_once("models/Adherent.php"); + +class ControleurAdherent +{ + public static function lireAdherents() + { + $adherents = Adherent::getAllAdherents(); + return view('adherents.liste-adherents', ['adherents' => $adherents]); + } +} \ No newline at end of file diff --git a/TP4/ex1/controller/ControleurAuteur.php b/TP4/ex1/controller/ControleurAuteur.php index 3a1f7612916216dc2a0dd05b410d36317417987c..304477314df310a973a2d2f5e839919dc6c58642 100644 --- a/TP4/ex1/controller/ControleurAuteur.php +++ b/TP4/ex1/controller/ControleurAuteur.php @@ -11,7 +11,7 @@ class ControleurAuteur public static function lireAuteur() { - if(empty($_GET["numAuteur"])){ + if (empty($_GET["numAuteur"])) { die("Le paramètre numAuteur n'est pas spécifié."); } $auteur = Auteur::getAuteurByNum($_GET["numAuteur"]); diff --git a/TP4/ex1/index.php b/TP4/ex1/index.php index 43e88f9c1b1734c417cafb96e58707cca66a0f1c..4d19a797563984853245d4ab13566540675bb6b8 100644 --- a/TP4/ex1/index.php +++ b/TP4/ex1/index.php @@ -6,6 +6,7 @@ error_reporting(E_ALL); require_once("config/Database.php"); require_once("helpers/views.php"); require_once("controller/ControleurAuteur.php"); +require_once("controller/ControleurAdherent.php"); Database::connect(); @@ -15,6 +16,9 @@ if(empty($_GET["action"])){ if(in_array($_GET["action"], get_class_methods('ControleurAuteur'))){ $action = $_GET["action"]; ControleurAuteur::$action(); + }elseif(in_array($_GET["action"], get_class_methods('ControleurAdherent'))){ + $action = $_GET["action"]; + ControleurAdherent::$action(); } } diff --git a/TP4/ex1/models/Adherent.php b/TP4/ex1/models/Adherent.php index 4441f93a60b210184bf6386e48e15740c1dc377a..13026fb49af7d3cd19427a1dc14368a40816ec26 100644 --- a/TP4/ex1/models/Adherent.php +++ b/TP4/ex1/models/Adherent.php @@ -33,6 +33,38 @@ class Adherent $this->numCategorie = $numCategorie; } + public function __set($property, $value){ + echo "test"; + if($property === "dateAdhesion"){ + $this->dateAdhesion = new DateTime($value); + }else{ + $this->$property = $value; + } + } + + public static function getAllAdherents(): array + { + // écriture de la requête + $requete = "SELECT * FROM Adherent;"; + // envoi de la requête et stockage de la réponse + $resultat = Database::pdo()->query($requete); + // traitement de la réponse + $resultat->setFetchmode(PDO::FETCH_ASSOC); + $resultat = $resultat->fetchAll(); + + $tableau = array(); + foreach ($resultat as $row){ + $tableau[] = new Adherent($row['login'], + $row['mdp'], + $row['nomAdherent'], + $row['prenomAdherent'], + $row['email'], + new DateTime($row['dateAdhesion']), + $row['numCategorie']); + } + return $tableau; + } + /** * @return string */ diff --git a/TP4/ex1/models/Auteur.php b/TP4/ex1/models/Auteur.php index 90b33d2cf362ff025b2b7976c82f1951643664a8..6a965130d1b031e783c526acc97f46354fa1b89b 100644 --- a/TP4/ex1/models/Auteur.php +++ b/TP4/ex1/models/Auteur.php @@ -3,9 +3,9 @@ class Auteur { // attributs - private int $numAuteur; - private string $nom; - private string $prenom; + private ?int $numAuteur; + private ?string $nom; + private ?string $prenom; private ?int $anneeNaissance; // getter diff --git a/TP4/ex1/resources/views/adherents/liste-adherents.php b/TP4/ex1/resources/views/adherents/liste-adherents.php new file mode 100644 index 0000000000000000000000000000000000000000..cc865eafab5dff39122a0c018c3f1c81b122a198 --- /dev/null +++ b/TP4/ex1/resources/views/adherents/liste-adherents.php @@ -0,0 +1,29 @@ +<html lang="fr"> +<head> + <meta charset="utf-8"> + <title>Liste des adhérents</title> + <?=view('layouts.head')?> +</head> +<body class=""> +<div class="container"> + <h1>Liste de tous les adhérents</h1> + <p>Voici la liste de tous les adhérents</p> + <div class="d-flex flex-wrap justify-content-between"> + <?php foreach ($adherents as $adherent) { ?> + <div class="card mb-2" style="width: 18rem;"> + <div class="card-body"> + <h5 class="card-title"><?=$adherent->getPrenomAdherent()?> <?=$adherent->getNomAdherent()?></h5> + <p class="card-text">ID: <?=$adherent->getLogin()?><br> + Date de naissance: <?=$adherent->getDateAdhesion()->format("Y-m-d")?></p> + <a class="btn btn-primary" + href="index.php?controller=controleurAuteur&action=lireAuteur&numAuteur=<?=$adherent->getLogin()?>"> + Lire les détails + </a> + </div> + </div> + <?php } ?> + </div> +</div> +<?=view('layouts.footer')?> +</body> +</html> \ No newline at end of file