Skip to content

Commit

Permalink
Fixed IsOffered = false and dvd deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsDyze committed Oct 13, 2024
1 parent 8dc24ee commit e61a59f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Controllers/Manage/ManageDVDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
11 changes: 9 additions & 2 deletions src/Services/DVDService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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");
Expand Down
6 changes: 1 addition & 5 deletions src/Services/DataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/Views/Manage/DVD/Detail/ManageDVDDetailView.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
🎬 <?php echo $data->DVD->LocalTitle; ?> 🎬
</h2>
<a class="custom-link" href="/Manage/DVD">Back to the list</a>

<form method="POST" action="" class="container">
<div class="side-nav section-block">
<a href="#General">General</a>
Expand All @@ -36,8 +35,6 @@
<div>
<h3 id="General">General</h3>
<input type="hidden" name="_METHOD" value="<?php echo $action; ?>"/>
<input type="hidden" name="Genres" />
<input type="hidden" name="TypeId" />
<?php echo $componentBuilder->getTextComponent("Title", "Titre", "Titre", $data->DVD->Title, true, false); ?>
<?php echo $componentBuilder->getTextComponent("LocalTitle", "Titre local", "Titre local", $data->DVD->LocalTitle, true, false); ?>
<?php echo $componentBuilder->getAreaComponent("Synopsis", "Synopsis", "Synopsis", $data->DVD->Synopsis, true, false); ?>
Expand Down Expand Up @@ -73,7 +70,6 @@
Y chez le client
Z perdus
</div>

<button type="submit">Save</button>
<button type="submit">Sauvegarder</button>
</div>
</form>
7 changes: 7 additions & 0 deletions src/Views/Manage/DVD/List/ManageDVDListView.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<th scope="col" onclick="orderBy('IsOffered')">Dans l'offre</th>
<th scope="col" onclick="orderBy('Price')">Prix</th>
<th scope="col" onclick="orderBy('Quantity')">Quantité</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
Expand All @@ -35,6 +36,12 @@
<th scope="col" class="col-short"><?php echo $row->IsOffered; ?></th>
<th scope="col" class="col-price"><?php echo number_format((float)$row->Price, 2, ',', '') . ""; ?></th>
<th scope="col" class="col-number"><?php echo $row->Quantity; ?></th>
<th scope="col" class="col-short">
<form method="POST" action="/manage/dvd/<?php echo $row->Id; ?>" class="container" onclick="event.stopPropagation()">
<input type="hidden" name="_METHOD" value="DELETE"/>
<button type="submit" title="delete">❌️</button>
</form>
</th>
</tr>
<?php endforeach ?>
</tbody>
Expand Down

0 comments on commit e61a59f

Please sign in to comment.