/
aanbodController.php
76 lines (63 loc) · 2.4 KB
/
aanbodController.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
66
67
68
69
70
71
72
73
74
75
<?php
/* andere uses */
use Pizza\Business\PizzaService;
use Doctrine\Common\ClassLoader;
require_once ("Doctrine/Common/ClassLoader.php");
require_once("libraries/Twig/Autoloader.php");
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem("src/Pizza/Presentation");
$twig = new Twig_Environment($loader);
$classLoader = new ClassLoader("Pizza", "src");
$classLoader->register();
session_start();
if (!(isset($_SESSION["winkelmandje"]))) {
$_SESSION["winkelmandje"] = array();
$_SESSION["totaalprijs"] = 0;
}
//$winkelmandje = array();
$psvc = new PizzaService();
$pizzaLijst = $psvc->haalPizzaOverzicht();
if (isset($_GET["keuze"])) {
$gekozenPizzaId = $_GET["keuze"];
$gekozenPizza = $psvc->haalPizza($gekozenPizzaId);
$_SESSION["totaalprijs"] += $gekozenPizza->getPrijs();
$_SESSION["winkelmandje"] = $psvc->vulWinkelmandje($gekozenPizza, $_SESSION["winkelmandje"]);
//$item = $psvc->vulWinkelmandje($gekozenPizza);
header("location:aanbodController.php");
exit(0);
} else if (isset($_GET["action"])) {
if ($_GET["action"] == "verwijderItem") {
$teVerwijderenPizzaId = $_GET["item"];
$teVerwijderenPizza = $psvc->haalPizza($teVerwijderenPizzaId);
$_SESSION["totaalprijs"] -= $teVerwijderenPizza->getPrijs();
//$_SESSION["winkelmandje"] = $psvc->verwijderWinkelmandje($teVerwijderenPizza, $_SESSION["winkelmandje"]);
$key=array_search($teVerwijderenPizza, $_SESSION["winkelmandje"]);
if($key!==false){
unset($_SESSION["winkelmandje"][$key]);
}
$_SESSION["winkelmandje"] = array_values($_SESSION["winkelmandje"]);
}
if ($_GET["action"] == "afrekenen") {
if (!empty($_SESSION["winkelmandje"])) {
if (isset($_SESSION["aangemeld"])) {
header("location:afrekenenController.php");
exit(0);
} else {
header("location:checkAccountController.php");
exit(0);
}
}else{
header("location:aanbodController.php");
}
}
if($_GET["action"] == "wijzig"){
$_SESSION["wijzig"] = true;
}
} else {
$gekozenPizzaId = "";
$gekozenPizza = "";
$keuzeGemaakt = false;
}
$view = $twig->render("aanbod.twig", array("pizzaLijst" => $pizzaLijst,
"winkelmandje" => $_SESSION["winkelmandje"], "totaalprijs" => $_SESSION["totaalprijs"]));
print($view);