From 0bf490d71759ce51b0783b4623efb7f82bd22e01 Mon Sep 17 00:00:00 2001
From: Sofiane Lasri <alasri250@gmail.com>
Date: Mon, 17 Oct 2022 10:58:33 +0200
Subject: [PATCH] =?UTF-8?q?Liste=20adh=C3=A9rents=20termin=C3=A9e.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 TP4/ex1/controller/ControleurAdherants.php    |  6 ----
 TP4/ex1/controller/ControleurAdherent.php     | 11 +++++++
 TP4/ex1/controller/ControleurAuteur.php       |  2 +-
 TP4/ex1/index.php                             |  4 +++
 TP4/ex1/models/Adherent.php                   | 32 +++++++++++++++++++
 TP4/ex1/models/Auteur.php                     |  6 ++--
 .../views/adherents/liste-adherents.php       | 29 +++++++++++++++++
 7 files changed, 80 insertions(+), 10 deletions(-)
 delete mode 100644 TP4/ex1/controller/ControleurAdherants.php
 create mode 100644 TP4/ex1/controller/ControleurAdherent.php
 create mode 100644 TP4/ex1/resources/views/adherents/liste-adherents.php

diff --git a/TP4/ex1/controller/ControleurAdherants.php b/TP4/ex1/controller/ControleurAdherants.php
deleted file mode 100644
index c83bf3e..0000000
--- 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 0000000..1cb10da
--- /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 3a1f761..3044773 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 43e88f9..4d19a79 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 4441f93..13026fb 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 90b33d2..6a96513 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 0000000..cc865ea
--- /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
-- 
GitLab