| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- /**
- * Inventory base entity file.
- *
- * Creates the entity and makes it available.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @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);
- }
- }
|