Skip to content
Snippets Groups Projects
Select Git revision
  • 9736a6be78912dffb76ed26fb88514d7800142d2
  • main default protected
2 results

ControleurLivre.php

Blame
  • ControleurLivre.php 1.51 KiB
    <?php
    require_once "ControleurObjet.php";
    require_once("models/Livre.php");
    
    class ControleurLivre extends ControleurObjet
    {
        protected static string $object = "Livre";
        /**
         * Charge la page de la liste des adhérents.
         * @return string
         * @throws Exception
         */
        public static function lireLivres(): string
        {
            $livres = Livre::getAllLivres();
    
            $objects = [];
            foreach ($livres as $livre){
                $object['id_name'] = "numLivre";
                $object['id_value'] = $livre->numLivre;
                $object['type'] = "Livre";
                $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', [
                'pageTitle' => 'Liste des livres',
                'pageDesc' => 'Voici la liste de tous les livres',
                'objects' => $objects
            ]);
        }
    
        /**
         * Charge la page du détail d'un adhérent.
         * @return string
         * @throws Exception
         */
        public static function lireLivre(): string
        {
            if (empty($_GET["numLivre"])) {
                die("Le paramètre numLivre n'est pas spécifié.");
            }
            $livre = Livre::getLivreByNumLivre($_GET["numLivre"]);
    
            return view('simple-data', [
                'pageTitle' => 'Information du livre',
                'pageContent' => $livre->afficher()
            ]);
        }
    }