-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcards.php
65 lines (60 loc) · 1.74 KB
/
cards.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
include_once("autoload.php");
session_start();
$prRep = new ProductRepository();
$prImRep = new ProductImageRepository();
$prCatRep = new ProductCategoryRepository();
$prCatRelRem = new ProductCategoryRelRepository();
if ($_POST['tri'] == "Prix Croissant") {
$criteria = "price";
$order = "ASC";
} elseif ($_POST['tri'] == "Prix Décroissant") {
$criteria = "price";
$order = "DESC";
} elseif ($_POST['tri'] == "Nouveaux produits") {
$criteria = "date";
$order = "DESC";
};
$minPrice = $_POST['minPrice'];
$maxPrice = $_POST['maxPrice'];
$categories = [];
foreach (array_slice($_POST, 3) as $key => $value) {
array_push($categories, $value);
}
if (empty($categories)) {
$products = $prRep->getProducts($minPrice, $maxPrice, $criteria, $order);
} else {
$products = $prCatRelRem->productByCat($minPrice, $maxPrice, $categories, $criteria, $order);
}
foreach ($products as $product) {
$image = $prImRep->findOneBy(array('productId' => $product['id']))
?>
<div class="productCard">
<div class="productImage">
<img src=<?php echo "data:image/jpeg;base64," . base64_encode($image['image']) ?> alt="">
</div>
<div class="productDetails">
<h4><?= $product['name']?></h4>
<h4><?= $product['price'] ?>Dt</h4>
<?php
if ($_SESSION['role'] == 'admin') {
?>
<a href="addProduct.php?edit=<?=$product['id']?>">
<i class="fas fa-pen"></i>
</a>
<a href="addProduct.php?remove=<?=$product['id']?>">
<i class="fas fa-times-circle"></i>
</a>
<?php } else {
?>
<a href="product.php?view=<?=$product['id']?>" >
<i class="fas fa-eye"></i>
<h4>View product</h4>
</a>
<?php }
?>
</div>
</div>
<?php
}
?>