-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScannedList.php
62 lines (47 loc) · 1.08 KB
/
ScannedList.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
<?php
class ScannedList {
private $list;
private $inventory;
public function __construct($inventory) {
$this->list = array();
$this->inventory = $inventory;
}
public function add($code) {
if(!$this->inventory->isInInventory($code)){
throw new Exception("product <b>" . $code . "</b> has not exist\n");
}
if (!$this->isInList($code)) {
$this->list[$code] = 1;
} else {
$this->list[$code]++;
}
}
public function getList(){
return $this->list;
}
public function getInventory(){
return $this->inventory;
}
public function get($code) {
if ($this->isInInventory($code))
return $this->list[$code];
}
public function clear() {
$this->list = array();
}
public function remove($code) {
unset($this->list[$code]);
}
public function isInInventory($code) {
return $this->inventory->isInInventory($code);
}
public function isInList($code){
return array_key_exists($code, $this->list);
}
public function getResult() {
foreach($this->list as $key=>$value) {
echo $key. " ". $value;
}
}
}
?>