* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::ENTITY . "Entity.php"); /** * An in-game existing item. * * Represents an object that exist in the game. * * @category Entity */ class Inventory extends Entity{ /** * @var int Item identifier. */ private $id; /** * @var string Item name. */ private $name; /** * @var string Item type. */ private $type; /** * @var string Item description. */ private $description; /** * Constructor. * * Searches the database and retrieves the information about the * building, populating it and it's items. * * @param int $id Item identifier. * @param int $type Item type identifier. Optional, will try to guess if null. */ public function __construct($id, $type = null){ $s = " SELECT inventory.id AS id, inventory.name AS name, inventory.description AS description, inventory_type.name AS type FROM inventory, inventory_type WHERE inventory.type = inventory_type.id AND inventory.id = :id "; if ($type != null){ $s .= "AND inventory.type = :type"; } $statement = get_context()->get_db()->prepare($s); $statement->bindValue(':id', $id, SQLITE3_TEXT); $statement->bindValue(':type', $type, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->type = $r["type"]; $this->id = $r["id"]; $this->name = HTML::e($r["name"]); $this->description = HTML::e($r["description"]); } } /** * Retrieves the owned item identifier. * * @return int Item ID. */ public function get_id(){ return $this->id; } /** * Retrieves the item name. * * @return string Item name. */ public function get_name(){ return $this->name; } /** * Retrieves the item type. * * @return int Item type. */ public function get_type(){ return $this->type; } /** * Retrieves the item description. * * @return string Item description. */ public function get_description(){ return $this->description; } /** * Gets the path to the item image. * * @return string Image URL, or a fixed unknown image. */ public function get_image(){ return APPLICATION::img("INVENTORY", $this->id); } }