aboutsummaryrefslogtreecommitdiffstats
path: root/inc/Inventory.inc
blob: 3396eb99b2aced9ea8d3d0659e0e8b23e39de5ea (plain)
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
<?php

class Inventory {

	public $items = array();

	public static function created() {
		return !empty($_SESSION["inventory"]);
	}

	public static function sendContent() {
		return self::get()->items;
	}

	public static function get() {
		if(!self::created()) {
			$_SESSION["inventory"] = new Inventory();
		}
		return $_SESSION["inventory"];
	}

	private function _addItem($item) {
		$counter = 0;
		foreach($this->items as $object){
			if($object[0] == $item){
				$counter++;
			}
		}
		$tab = array($item,$counter+1);
		$this->items[] = $tab;
		return $tab;
	}

	public static function addItem($item) {
		$inv = self::get();
		$tab = $inv->_addItem($item);
		return $tab;
	}

	private function _removeItem($item) {
		unset($this->items[array_search($item, $this->items)]);
	}

	public static function removeItem($item) {
		$inv = self::get();
		$inv->_removeItem($item);
	}
	
}

?>