diff --git a/controller/ControleurAdherent.php b/controller/ControleurAdherent.php index 390ab02eb069c8b2897ffcaf5f1d0350ee89cd83..c8611b06e5f640d224b13e0472a44617b14d4d16 100644 --- a/controller/ControleurAdherent.php +++ b/controller/ControleurAdherent.php @@ -15,6 +15,9 @@ class ControleurAdherent extends ControleurObjet $adherents = Adherent::getAllAdherents(); $objects = []; foreach ($adherents as $adherent){ + $object['id_name'] = "login"; + $object['id_value'] = $adherent->login; + $object['type'] = "Adherent"; $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"; diff --git a/controller/ControleurAuteur.php b/controller/ControleurAuteur.php index 7936ad2d7aba3fa897c92de1c8f23b70f5350078..eddce328250c50017d782063c9706fac51900f4b 100644 --- a/controller/ControleurAuteur.php +++ b/controller/ControleurAuteur.php @@ -16,6 +16,9 @@ class ControleurAuteur extends ControleurObjet $objects = []; foreach ($auteurs as $auteur){ + $object['id_name'] = "numAuteur"; + $object['id_value'] = $auteur->numAuteur; + $object['type'] = "Auteur"; $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"; diff --git a/controller/ControleurLivre.php b/controller/ControleurLivre.php index f3ab48a74dfefd34452e8ce5815f60f36bc63fca..f3c14a4764295687e14153ae8c70d673130eedb7 100644 --- a/controller/ControleurLivre.php +++ b/controller/ControleurLivre.php @@ -16,6 +16,9 @@ class ControleurLivre extends ControleurObjet $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"; diff --git a/controller/ControleurObjet.php b/controller/ControleurObjet.php index 039a97bc7fce2f3472a0237abfe25be4167f33cd..a97605d0626b880b276cca9fa30f0e3945a6c8ee 100644 --- a/controller/ControleurObjet.php +++ b/controller/ControleurObjet.php @@ -49,8 +49,10 @@ class ControleurObjet public static function modifyObject() : string { - if(!empty($_GET["tableName"]) && !empty($_GET["id"])){ + if(!empty($_GET["tableName"]) && !empty($_GET["id_name"]) && !empty($_GET["id_value"])){ + $object = Objet::getObject($_GET["tableName"], ['name' => $_GET["id_name"], 'value' => $_GET["id_value"]]); + return json_encode($object); } return ""; } diff --git a/index.php b/index.php index 029da6f8a20b26b664f8a753cfe7a644024c5909..60e332d315a14601ec276e082cd7fb9b002ec050 100644 --- a/index.php +++ b/index.php @@ -29,6 +29,7 @@ if (empty($_REQUEST["action"])) { "lireLivre" => ControleurLivre::lireLivre(), "lireLivres" => ControleurLivre::lireLivres(), "describeTable" => ControleurObjet::describeTable(), + "modifierObjet" => ControleurObjet::modifyObject(), default => ControleurAuteur::lireAuteur(), }; } catch (Exception $e) { diff --git a/models/Objet.php b/models/Objet.php index 43cd3e8b08754cebc666c51b402fe55787ea7871..1ed669f0617df7789b4149da70caaa7067b760ca 100644 --- a/models/Objet.php +++ b/models/Objet.php @@ -42,7 +42,6 @@ class Objet public static function addObject(String $tableName, array $columns) : array { $result["status"] = "success"; - $result["message"] = "Insertion réussie"; $validation = Objet::verifyTableAndFormat($tableName, $columns); if($validation["status"] !== "success"){ @@ -109,7 +108,6 @@ class Objet public static function modifyObject(String $tableName, array $id, array $columns) : array { $result["status"] = "success"; - $result["message"] = "Modification réussie"; $validation = Objet::verifyTableAndFormat($tableName, $columns); if($validation["status"] !== "success"){ @@ -163,7 +161,7 @@ class Objet $insertQuery = Database::pdo()->prepare($queryString); try{ // Et on l'exécute - $insertQuery->execute([$id["name"]]); + $insertQuery->execute([$id["value"]]); } catch (PDOException $e) { return [ "status" => "fail", @@ -174,7 +172,6 @@ class Objet return [ "status" => "success", - "message" => "Récupération réussie.", "data" => $insertQuery->fetch(PDO::FETCH_ASSOC) ]; } diff --git a/resources/views/data-grid.php b/resources/views/data-grid.php index 982e309dfd97fcf9b4721c187e0fcb30201276a2..ee77f586d73e0c669e5def0ee11c52a36ab08e5b 100644 --- a/resources/views/data-grid.php +++ b/resources/views/data-grid.php @@ -18,6 +18,10 @@ href="{{ $object['url'] }}"> Lire les détails </a> + <a class="btn btn-outline-primary" + href="index.php?action=modifierObjet&tableName={{ $object['type'] }}&id_name={{ $object['id_name'] }}&id_value={{ $object['id_value'] }}"> + Modifier + </a> </div> </div> @endforeach