Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app/controllers/ProductController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require __DIR__ .'/../models/Product.php';

class ProductController {
private $productModel;

public function __construct(PDO $dbConnection) {
$this->productModel = new Product($dbConnection);
}

public function viewProducts() {
$title = "View Products";
$products = $this->productModel->getAll();
require_once __DIR__ . "/../views/products.php";
}
}
8 changes: 0 additions & 8 deletions src/app/controllers/products.php

This file was deleted.

34 changes: 34 additions & 0 deletions src/app/models/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

class Product
{

private $conn;

public function __construct(PDO $dbConnection) {
$this->conn = $dbConnection;
}

public function create($id, $name, $description, $price, $supplier_id) {
$query = "INSERT INTO product (id, name, description, prince, supplier_id)
VALUES (:id, :name, :description, :price, :supplier_id)";

$stmt = $this->conn->prepare($query);
$stmt->bindValue(":id", $id);
$stmt->bindValue(":name", $name);
$stmt->bindValue(":description", $description);
$stmt->bindValue(":price", $price);
$stmt->bindValue(":supplier_id", $supplier_id);

return $stmt->execute();
}

public function getAll() {
$query = "SELECT * FROM product";

$stmt = $this->conn->prepare($query);

$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
}
}
10 changes: 0 additions & 10 deletions src/app/models/product.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/views/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
</div>";
}
?>
</div>
</div>
3 changes: 2 additions & 1 deletion src/app/views/partials/navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div class="container">
<ul class="pages-list">
<li><a href="/">Home</a></li>
<li><a href="/products">Products list</a></li>
<?php if ($userId) { ?>
<li><a href="#">Order</a></li>
<li><a href="/account">My account</a></li>
Expand All @@ -20,4 +21,4 @@
<?php } ?>
</ul>
</div>
</nav>
</nav>
17 changes: 6 additions & 11 deletions src/app/views/products.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
<?php require_once '../controllers/products.php' ?>
<?php include 'partials/header.php'; ?>
<?php if (!isset($_SESSION['user'])): ?>
<div role="alert">
You have to be signed-in to view this page.
</div>
<?php include 'partials/footer.php'; ?>
<?php exit; ?>
<?php endif; ?>

<div>
<h1>Product list</h1>
<!--FIXME: fix category table, to organise products by category (those seen on the menu)-->
<?php

foreach ($products as $product) {
echo "<div>
<p>" . $product->name . "</p>
<p>" . $product->price . "</p>
<p>" . $product->name . " - " . $product->price . "€</p>

<!--
<form method='POST' action='index.php'>
<input type='hidden' name='product_id' value='" . $product->id . "'>
<button type='submit' name='action' value='add'>Add to Cart</button>
<button type='submit' name='action' value='remove'>Remove one</button>
</form>
-->
</div>";
}
?>
</div>
<?php include 'partials/footer.php'; ?>
<?php include 'partials/footer.php'; ?>
3 changes: 2 additions & 1 deletion src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
'/sign-out' => ['AuthController', 'signOut'],
'/account' => ['AuthController', 'viewAccount'],
'/account-data' => ['AuthController', 'getAccountData'],
'/products' => ['ProductController', 'viewProducts']
],
'POST' => [
'/sign-in' => ['AuthController', 'signIn'],
'/sign-up' => ['AuthController', 'signUp'],
],
];
];