Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projects/slutprojekt/incl/classes/
Order.php
115 lines UTF-8 Windows (CRLF)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
class Order
{
private ?int $order_id;
private int $item_id;
private int $customer_id;
private int $restaurant_id;
private string $status;
private string $price;
private string $token;
private ?string $created_at;
private ?Menu_Item $menuItem = null;
public function __construct(int $item_id, int $customer_id, int $restaurant_id, string $status, string $price, string $token, ?int $order_id = null, ?string $created_at = null)
{
$this->order_id = $order_id;
$this->item_id = $item_id;
$this->customer_id = $customer_id;
$this->restaurant_id = $restaurant_id;
$this->status = $status;
$this->price = $price;
$this->token = $token;
$this->created_at = $created_at;
}
// Statiska metoder för att initiera nya instanser av klassen
public static function create_new(int $item_id, int $customer_id, int $restaurant_id, string $status, string $price)
{
$token = bin2hex(random_bytes(20));
return new self($item_id, $customer_id, $restaurant_id, $status, $price, $token);
}
public static function init_from_db(int $item_id, int $customer_id, int $restaurant_id, string $status, string $price, string $token, int $order_id, string $created_at)
{
return new self($item_id, $customer_id, $restaurant_id, $status, $price, $token, $order_id, $created_at);
}
// Metoder för att hämta data
public function get_order_id()
{
return $this->order_id;
}
public function get_item_id()
{
return $this->item_id;
}
public function get_customer_id()
{
return $this->customer_id;
}
public function get_restaurant_id()
{
return $this->restaurant_id;
}
public function get_status()
{
return $this->status;
}
public function get_price()
{
return $this->price;
}
public function get_token()
{
return $this->token;
}
public function get_creation_timestamp()
{
return $this->created_at;
}
public function set_menu_item(Menu_Item $menuItem): void
{
$this->menuItem = $menuItem;
}
public function get_menu_item(): ?Menu_Item
{
return $this->menuItem;
}
public function toArray(): array
{
$data = [
'id' => $this->order_id,
'item_id' => $this->item_id,
'customer_id' => $this->customer_id,
'restaurant_id' => $this->restaurant_id,
'status' => $this->status,
'price' => $this->price,
'token' => $this->token,
'created_at' => $this->created_at,
];
if ($this->menuItem !== null) {
// Include menu item details inline
$data['item_name'] = $this->menuItem->get_item_name();
$data['item_description'] = $this->menuItem->get_item_description();
$data['item_price'] = $this->menuItem->get_item_price();
$data['item_enabled'] = $this->menuItem->get_item_enabled();
$data['item_image'] = $this->menuItem->get_item_image();
}
return $data;
}
}