diff --git a/src/Controllers/BaseController.php b/src/Controllers/BaseController.php index e1f6e0b..9a995c7 100644 --- a/src/Controllers/BaseController.php +++ b/src/Controllers/BaseController.php @@ -20,7 +20,7 @@ public function patch(): void { http_response_code(405); } - public function delete(): void + public function delete(int $id): void { http_response_code(405); } diff --git a/src/Controllers/Manage/ManageDVDController.php b/src/Controllers/Manage/ManageDVDController.php index bdfd9d4..5fa2cff 100644 --- a/src/Controllers/Manage/ManageDVDController.php +++ b/src/Controllers/Manage/ManageDVDController.php @@ -138,6 +138,16 @@ public function post(): void die(); } + public function delete($id): void + { + $service = new DVDService(); + + $newId = $service->delete($id); + + header("Location: /manage/dvd"); + die(); + } + private function postToDvdModel(DVDModel $model) { $model->Title = $_POST["Title"]; diff --git a/src/Services/DVDService.php b/src/Services/DVDService.php index 136bda6..c35d888 100644 --- a/src/Services/DVDService.php +++ b/src/Services/DVDService.php @@ -299,7 +299,7 @@ public function update(DVDModel $dvd) ->set("Notation", $dvd->Notation) ->set("Certification", $dvd->Certification) ->set("Note", $dvd->Note) - ->set("IsOffered", $dvd->IsOffered) + ->set("IsOffered", (int)($dvd->IsOffered??false)) ->set("Quantity", $dvd->Quantity) ->set("Price", $dvd->Price) ->set("Year", $dvd->Year) @@ -324,7 +324,7 @@ public function insert(DVDModel $dvd) ->value("Notation", $dvd->Notation) ->value("Certification", $dvd->Certification) ->value("Note", $dvd->Note) - ->value("IsOffered", $dvd->IsOffered) + ->value("IsOffered", (int)($dvd->IsOffered??false)) ->value("Quantity", $dvd->Quantity) ->value("Price", $dvd->Price) ->value("Year", $dvd->Year) @@ -337,6 +337,13 @@ public function insert(DVDModel $dvd) return $this->insertStatement($query->sql, $query->params); } + public function delete(int $id) + { + $query = "DELETE FROM dvds WHERE Id = ?;"; + + return $this->executeStatement($query, [$id]); + } + function isAllowedOrderColumn(string $column): bool { $allowedOrderColumns = array("Quantity", "Year", "Title", "IsOffered", "Price", "Notation"); diff --git a/src/Services/DataService.php b/src/Services/DataService.php index b202aff..3af1ad1 100644 --- a/src/Services/DataService.php +++ b/src/Services/DataService.php @@ -83,11 +83,7 @@ protected function getDBContext() protected function executeStatement($statement, $parameters) { - if (substr_count($statement, "?") == array_count_values($parameters)) - { - echo "Too few or too many parameters for the provided statement"; - die(); - } + $this->validateStatementAndParameters($statement, $parameters); $query = $this->GetDBContext()->prepare($statement); return $query->execute($parameters); diff --git a/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php b/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php index 2ba09a6..505d5eb 100644 --- a/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php +++ b/src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php @@ -22,7 +22,6 @@ 🎬 DVD->LocalTitle; ?> 🎬 Back to the list -
General @@ -36,8 +35,6 @@

General

- - getTextComponent("Title", "Titre", "Titre", $data->DVD->Title, true, false); ?> getTextComponent("LocalTitle", "Titre local", "Titre local", $data->DVD->LocalTitle, true, false); ?> getAreaComponent("Synopsis", "Synopsis", "Synopsis", $data->DVD->Synopsis, true, false); ?> @@ -73,7 +70,6 @@ Y chez le client Z perdus
- - +
diff --git a/src/Views/Manage/DVD/List/ManageDVDListView.template.php b/src/Views/Manage/DVD/List/ManageDVDListView.template.php index 75ca43e..c09bd7b 100644 --- a/src/Views/Manage/DVD/List/ManageDVDListView.template.php +++ b/src/Views/Manage/DVD/List/ManageDVDListView.template.php @@ -25,6 +25,7 @@ Dans l'offre Prix Quantité + Action @@ -35,6 +36,12 @@ IsOffered; ?> Price, 2, ',', '') . " € "; ?> Quantity; ?> + +
+ + +
+