aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-04-24 22:06:40 +0200
committerpiernov <piernov@piernov.org>2016-04-24 22:06:40 +0200
commit38a80dc6468c7e7cfaa4e22d4e4b8e3b374cf388 (patch)
treeeffb3ae18b551d45de1debccf79db985a3674ffe /inc
parent6dea6c0fbbc748e417076e7ca0d7773452b1bb57 (diff)
downloadcandybox-38a80dc6468c7e7cfaa4e22d4e4b8e3b374cf388.tar.gz
candybox-38a80dc6468c7e7cfaa4e22d4e4b8e3b374cf388.tar.bz2
candybox-38a80dc6468c7e7cfaa4e22d4e4b8e3b374cf388.tar.xz
candybox-38a80dc6468c7e7cfaa4e22d4e4b8e3b374cf388.zip
Add PHP Inventory class
Diffstat (limited to 'inc')
-rw-r--r--inc/Inventory.inc41
1 files changed, 41 insertions, 0 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
new file mode 100644
index 0000000..efe54f2
--- /dev/null
+++ b/inc/Inventory.inc
@@ -0,0 +1,41 @@
+<?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) {
+ $this->items[] = $item;
+ }
+
+ public static function addItem($item) {
+ $inv = self::get();
+ $inv->_addItem($item);
+ }
+
+ private function _removeItem($item) {
+ unset($this->items[array_search($item, $this->items)]);
+ }
+
+ public static function removeItem($item) {
+ $inv = self::get();
+ $inv->_removeItem($item);
+ }
+}
+
+?>