diff options
author | piernov <piernov@piernov.org> | 2016-04-25 22:36:33 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-04-25 22:36:33 +0200 |
commit | 54635d17eef27eb2546d69599e4107b242509ced (patch) | |
tree | 86d18cbb6e021b78ba1ce87307447d71d1802ad3 /inc/Inventory.inc | |
parent | f98b06a25d71cc02bf29d7c525da0095688ea872 (diff) | |
parent | 8140617aeb2f32f7095a443ca743c6d6915739c6 (diff) | |
download | candybox-54635d17eef27eb2546d69599e4107b242509ced.tar.gz candybox-54635d17eef27eb2546d69599e4107b242509ced.tar.bz2 candybox-54635d17eef27eb2546d69599e4107b242509ced.tar.xz candybox-54635d17eef27eb2546d69599e4107b242509ced.zip |
Merge branch 'alexichi' of ssh://piernov.org/srv/git/candybox into alexichi
Diffstat (limited to 'inc/Inventory.inc')
-rw-r--r-- | inc/Inventory.inc | 41 |
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); + } +} + +?> |