Skip to content
Snippets Groups Projects
Select Git revision
  • 8e64146941161c536feb31ca5594e4e9c2ed6c7d
  • main default protected
2 results

Adherent.php

Blame
  • Adherent.php 4.81 KiB
    <?php
    
    /**
     *
     */
    class Adherent
    {
        private string $login;
        private string $mdp;
        private string $nomAdherent;
        private string $prenomAdherent;
        private string $email;
        private DateTime $dateAdhesion;
        private int $numCategorie;
    
        /**
         * @param string $login
         * @param string $mdp
         * @param string $nomAdherent
         * @param string $prenomAdherent
         * @param string $email
         * @param DateTime $dateAdhesion
         * @param int $numCategorie
         */
        public function __construct(string $login, string $mdp, string $nomAdherent, string $prenomAdherent, string $email, DateTime $dateAdhesion, int $numCategorie)
        {
            $this->login = $login;
            $this->mdp = $mdp;
            $this->nomAdherent = $nomAdherent;
            $this->prenomAdherent = $prenomAdherent;
            $this->email = $email;
            $this->dateAdhesion = $dateAdhesion;
            $this->numCategorie = $numCategorie;
        }
    
        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;
        }
    
        public static function getAdherentByLogin($login) : Adherent
        {
            // écriture de la requête
            $requetePreparee = "SELECT * FROM Adherent WHERE login = :login;";
            $req_prep = Database::pdo()->prepare($requetePreparee);
            // le tableau des valeurs
            $valeurs = array("login" => $login);
            $response = null;
            try {
                // envoi de la requête
                $req_prep->execute($valeurs);
                // traitement de la réponse
                $req_prep->setFetchmode(PDO::FETCH_ASSOC);
                // récupération de l'auteur
                $row = $req_prep->fetch();
                $response = new Adherent($row['login'],
                    $row['mdp'],
                    $row['nomAdherent'],
                    $row['prenomAdherent'],
                    $row['email'],
                    new DateTime($row['dateAdhesion']),
                    $row['numCategorie']);
    
            } catch (PDOException $e) {
                echo $e->getMessage();
            }
            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 void
         */
        public function afficher(){
            echo "<p>" . $this->prenomAdherent . " " . $this->nomAdherent . " a rejoint le "
                .$this->dateAdhesion->format('Y-m-d H:i:s');
        }
    }