From 029a49fb179df4cacd10e738f10dd0cd0a91bc82 Mon Sep 17 00:00:00 2001
From: Sofiane Lasri <alasri250@gmail.com>
Date: Thu, 27 Oct 2022 23:53:18 +0200
Subject: [PATCH] Fin de TP4 ex5.

---
 TP4/ex1/controller/ControleurAdherent.php |   6 +-
 TP4/ex1/controller/ControleurAuteur.php   |   6 +-
 TP4/ex1/controller/ControleurLivre.php    |   6 +-
 TP4/ex1/models/Adherent.php               | 132 ++--------------------
 TP4/ex1/models/Auteur.php                 |  59 +---------
 TP4/ex1/models/Livre.php                  |  75 +-----------
 TP4/ex1/models/Objet.php                  |  27 +++++
 7 files changed, 57 insertions(+), 254 deletions(-)
 create mode 100644 TP4/ex1/models/Objet.php

diff --git a/TP4/ex1/controller/ControleurAdherent.php b/TP4/ex1/controller/ControleurAdherent.php
index bf36073..7d80d9c 100644
--- a/TP4/ex1/controller/ControleurAdherent.php
+++ b/TP4/ex1/controller/ControleurAdherent.php
@@ -13,9 +13,9 @@ class ControleurAdherent
         $adherents = Adherent::getAllAdherents();
         $objects = [];
         foreach ($adherents as $adherent){
-            $object['title'] = $adherent->getPrenomAdherent() . " " . $adherent->getNomAdherent();
-            $object['desc'] = "ID: {$adherent->getLogin()}<br>Date d'adhésion: {$adherent->getDateAdhesion()->format("Y-m-d")}";
-            $object['url'] = "index.php?action=lireAdherent&login={$adherent->getLogin()}";
+            $object['title'] = $adherent->prenomAdherent . " " . $adherent->nomAdherent;
+            $object['desc'] = "ID: {$adherent->login}<br>Date d'adhésion: {$adherent->dateAdhesion->format("Y-m-d")}";
+            $object['url'] = "index.php?action=lireAdherent&login={$adherent->login}";
             $objects[] = $object;
         }
         return view('data-grid', [
diff --git a/TP4/ex1/controller/ControleurAuteur.php b/TP4/ex1/controller/ControleurAuteur.php
index ec6ce17..694801e 100644
--- a/TP4/ex1/controller/ControleurAuteur.php
+++ b/TP4/ex1/controller/ControleurAuteur.php
@@ -16,9 +16,9 @@ class ControleurAuteur
 
         $objects = [];
         foreach ($auteurs as $auteur){
-            $object['title'] = $auteur->getPrenom() . " " . $auteur->getNom();
-            $object['desc'] = "ID: {$auteur->getNumAuteur()}<br>Date de naissance: {$auteur->getAnneeNaissance()}";
-            $object['url'] = "index.php?action=lireAuteur&numAuteur={$auteur->getNumAuteur()}";
+            $object['title'] = $auteur->prenom . " " . $auteur->nom;
+            $object['desc'] = "ID: {$auteur->numAuteur}<br>Date de naissance: {$auteur->anneeNaissance}";
+            $object['url'] = "index.php?action=lireAuteur&numAuteur={$auteur->numAuteur}";
             $objects[] = $object;
         }
         return view('data-grid', [
diff --git a/TP4/ex1/controller/ControleurLivre.php b/TP4/ex1/controller/ControleurLivre.php
index bdbaca9..6cf4d2a 100644
--- a/TP4/ex1/controller/ControleurLivre.php
+++ b/TP4/ex1/controller/ControleurLivre.php
@@ -14,9 +14,9 @@ class ControleurLivre
 
         $objects = [];
         foreach ($livres as $livre){
-            $object['title'] = $livre->getTitre();
-            $object['desc'] = "ID: {$livre->getNumLivre()}<br>Année de parution: {$livre->getAnneeParution()}";
-            $object['url'] = "index.php?action=lireLivre&numLivre={$livre->getNumLivre()}";
+            $object['title'] = $livre->titre;
+            $object['desc'] = "ID: {$livre->numLivre}<br>Année de parution: {$livre->anneeParution}";
+            $object['url'] = "index.php?action=lireLivre&numLivre={$livre->numLivre}";
             $objects[] = $object;
         }
         return view('data-grid', [
diff --git a/TP4/ex1/models/Adherent.php b/TP4/ex1/models/Adherent.php
index 218c253..58668a7 100644
--- a/TP4/ex1/models/Adherent.php
+++ b/TP4/ex1/models/Adherent.php
@@ -1,17 +1,15 @@
 <?php
+require_once "Objet.php";
 
-/**
- *
- */
-class Adherent
+class Adherent extends Objet
 {
-    private string $login;
-    private string $mdp;
-    private string $nomAdherent;
-    private string $prenomAdherent;
-    private string $email;
-    private DateTime $dateAdhesion;
-    private int $numCategorie;
+    protected string $login;
+    protected string $mdp;
+    protected string $nomAdherent;
+    protected string $prenomAdherent;
+    protected string $email;
+    protected DateTime $dateAdhesion;
+    protected int $numCategorie;
 
     /**
      * @param string $login
@@ -95,118 +93,6 @@ class Adherent
         return $response;
     }
 
-    /**
-     * @return string
-     */
-    public function getLogin(): string
-    {
-        return $this->login;
-    }
-
-    /**
-     * @param string $login
-     */
-    public function setLogin(string $login): void
-    {
-        $this->login = $login;
-    }
-
-    /**
-     * @return string
-     */
-    public function getMdp(): string
-    {
-        return $this->mdp;
-    }
-
-    /**
-     * @param string $mdp
-     */
-    public function setMdp(string $mdp): void
-    {
-        $this->mdp = $mdp;
-    }
-
-    /**
-     * @return string
-     */
-    public function getNomAdherent(): string
-    {
-        return $this->nomAdherent;
-    }
-
-    /**
-     * @param string $nomAdherent
-     */
-    public function setNomAdherent(string $nomAdherent): void
-    {
-        $this->nomAdherent = $nomAdherent;
-    }
-
-    /**
-     * @return string
-     */
-    public function getPrenomAdherent(): string
-    {
-        return $this->prenomAdherent;
-    }
-
-    /**
-     * @param string $prenomAdherent
-     */
-    public function setPrenomAdherent(string $prenomAdherent): void
-    {
-        $this->prenomAdherent = $prenomAdherent;
-    }
-
-    /**
-     * @return string
-     */
-    public function getEmail(): string
-    {
-        return $this->email;
-    }
-
-    /**
-     * @param string $email
-     */
-    public function setEmail(string $email): void
-    {
-        $this->email = $email;
-    }
-
-    /**
-     * @return DateTime
-     */
-    public function getDateAdhesion(): DateTime
-    {
-        return $this->dateAdhesion;
-    }
-
-    /**
-     * @param DateTime $dateAdhesion
-     */
-    public function setDateAdhesion(DateTime $dateAdhesion): void
-    {
-        $this->dateAdhesion = $dateAdhesion;
-    }
-
-    /**
-     * @return int
-     */
-    public function getNumCategorie(): int
-    {
-        return $this->numCategorie;
-    }
-
-    /**
-     * @param int $numCategorie
-     */
-    public function setNumCategorie(int $numCategorie): void
-    {
-        $this->numCategorie = $numCategorie;
-    }
-
     /**
      * @return string
      */
diff --git a/TP4/ex1/models/Auteur.php b/TP4/ex1/models/Auteur.php
index e0d2c52..2dd8482 100644
--- a/TP4/ex1/models/Auteur.php
+++ b/TP4/ex1/models/Auteur.php
@@ -1,12 +1,13 @@
 <?php
+require_once "Objet.php";
 
-class Auteur
+class Auteur extends Objet
 {
 	// attributs
-    private ?int $numAuteur;
-    private ?string $nom;
-    private ?string $prenom;
-    private ?int $anneeNaissance;
+    protected ?int $numAuteur;
+    protected ?string $nom;
+    protected ?string $prenom;
+    protected ?int $anneeNaissance;
 
     // getter
 
@@ -55,54 +56,6 @@ class Auteur
         return $response;
     }
 
-    public function getNumAuteur()
-    {
-        return $this->numAuteur;
-    }
-
-    // setter
-
-    public function setNumAuteur($nu)
-    {
-        $this->numAuteur = $nu;
-    }
-
-    public function getNom()
-    {
-        return $this->nom;
-    }
-
-    public function setNom($n)
-    {
-        $this->nom = $n;
-    }
-
-    public function getPrenom()
-    {
-        return $this->prenom;
-    }
-
-    // un constructeur
-
-    public function setPrenom($p)
-    {
-        $this->prenom = $p;
-    }
-
-    // une methode d'affichage.
-
-    public function getAnneeNaissance()
-    {
-        return $this->anneeNaissance;
-    }
-
-    // méthode static qui retourne les auteurs en un tableau d'objets
-
-    public function setAnneeNaissance($a)
-    {
-        $this->anneeNaissance = $a;
-    }
-
     // méthode static qui retourne un auteur identifié par son numAuteur
 
     public function afficher()
diff --git a/TP4/ex1/models/Livre.php b/TP4/ex1/models/Livre.php
index 40a343f..bde6024 100644
--- a/TP4/ex1/models/Livre.php
+++ b/TP4/ex1/models/Livre.php
@@ -1,11 +1,12 @@
 <?php
+require_once "Objet.php";
 
-class Livre
+class Livre extends Objet
 {
-    private int $numLivre;
-    private string $titre;
-    private int $anneeParution;
-    private int $numGenre;
+    protected int $numLivre;
+    protected string $titre;
+    protected int $anneeParution;
+    protected int $numGenre;
 
     /**
      * @param int $numLivre
@@ -63,70 +64,6 @@ class Livre
         return $response;
     }
 
-    /**
-     * @return int
-     */
-    public function getNumLivre(): int
-    {
-        return $this->numLivre;
-    }
-
-    /**
-     * @param int $numLivre
-     */
-    public function setNumLivre(int $numLivre): void
-    {
-        $this->numLivre = $numLivre;
-    }
-
-    /**
-     * @return string
-     */
-    public function getTitre(): string
-    {
-        return $this->titre;
-    }
-
-    /**
-     * @param string $titre
-     */
-    public function setTitre(string $titre): void
-    {
-        $this->titre = $titre;
-    }
-
-    /**
-     * @return int
-     */
-    public function getAnneeParution(): int
-    {
-        return $this->anneeParution;
-    }
-
-    /**
-     * @param int $anneeParution
-     */
-    public function setAnneeParution(int $anneeParution): void
-    {
-        $this->anneeParution = $anneeParution;
-    }
-
-    /**
-     * @return int
-     */
-    public function getNumGenre(): int
-    {
-        return $this->numGenre;
-    }
-
-    /**
-     * @param int $numGenre
-     */
-    public function setNumGenre(int $numGenre): void
-    {
-        $this->numGenre = $numGenre;
-    }
-
     /**
      * @return string
      */
diff --git a/TP4/ex1/models/Objet.php b/TP4/ex1/models/Objet.php
new file mode 100644
index 0000000..193f198
--- /dev/null
+++ b/TP4/ex1/models/Objet.php
@@ -0,0 +1,27 @@
+<?php
+require_once "Objet.php";
+
+/**
+ * Implémente les magic methods.
+ */
+class Objet
+{
+    /**
+     * @param $name
+     * @return mixed
+     */
+    public function __get($name)
+    {
+        return $this->$name ?? null;
+    }
+
+    /**
+     * @param $name
+     * @param $value
+     * @return void
+     */
+    public function __set($name, $value)
+    {
+        $this->$name = $value;
+    }
+}
\ No newline at end of file
-- 
GitLab