diff --git a/TP4/ex1/controller/ControleurAdherent.php b/TP4/ex1/controller/ControleurAdherent.php index bf36073b46d229afb791b8dd03f48f04f283f9c6..7d80d9c265b757d991724bf27a0370899ac26420 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 ec6ce17d8d7f8192fcd8c6e1abcc35f50bd69ade..694801e3c6d3b691c75a94bf00198dd506bba2ba 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 bdbaca9a7fdc3480e014db3b227392413b88f861..6cf4d2ab57c7dbbdbf7a3a1c26ca42bbaa7763e5 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 218c2533976ec2cc9487dd4aeae0185d4b2782dc..58668a7f6f7f91b275d599571e2b97ed9d5a928e 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 e0d2c52781b4b05c2c4545d9acb918b89a321bc1..2dd8482a287340f93b1568623434de0dac5296a2 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 40a343fc7a1b1fbb1577fa9a2ce82db7f60a32a6..bde6024f752931bccd03f7fef748ea6955b78cea 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 0000000000000000000000000000000000000000..193f198e2ca8ae1128035fbfe7864d4686e3766c --- /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