| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- /**
- * Inventory entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "K_Unit.php");
- /**
- * An inventory item.
- *
- * Represents an object from the table 'inventory'.
- *
- * @category Entity
- */
- class Inventory extends Entity{
- /**
- * @var int Owner identifier.
- */
- public $uid;
- /**
- * @var int|K_Unit Item identifier. If its a monster piece, a K_Unit entity.
- */
- public $id;
- /**
- * @var string Item name.
- */
- public $name;
- /**
- * @var string Item type name.
- */
- public $type;
- /**
- * @var int Item owned amount.
- */
- public $amount;
- /**
- * @var bool Indicates if the item are monster pieces.
- */
- public $is_monster_pices;
- /**
- * 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.
- * @global resource Database connection.
- */
- public function __construct($id, $type = null){
- global $db;
- $s = "
- SELECT
- inventory.id AS id,
- k_inventory.name AS name,
- k_inventory.description AS description,
- inventory.type AS type_ref,
- k_inventory_type.name AS type,
- inventory.amount AS amount
- FROM
- inventory,
- k_inventory,
- k_inventory_type
- WHERE
- inventory.type = k_inventory_type.id AND
- inventory.id = k_inventory.id AND
- inventory.type = k_inventory.type AND
- inventory.id = :id
- ";
- if ($type != null){
- $s .= "AND inventory.type = :type";
- }
- $statement = $db->prepare($s);
- $statement->bindValue(':id', $id, SQLITE3_INTEGER);
- $statement->bindValue(':type', $type, SQLITE3_INTEGER);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->type = $r["type"];
- $this->amount = $r["amount"];
- if ($r["type"] == INVENTORY_TYPE_ID::GUILD_MONSTER_PIECE || $r["type"] == INVENTORY_TYPE_ID::MONSTER_PIECE){
- $this->is_monster_pices = true;
- $this->id = new K_Unit($r["id"]);
- $this->name = HTML::e($this->id->title) . " Pieces";
- $this->description = HTML::e($this->id->title) . " Pieces";
- }
- else{
- $this->is_monster_pices = false;
- $this->id = $r["id"];
- $this->name = HTML::e($r["name"]);
- $this->description = HTML::e($r["description"]);
- }
- }
- }
- /**
- * Gets the path to the item image. The image must be in the
- * img/content/inventory/ directory, and its name must be the item id,
- * padded with '0' to 9 digites, and the extension must be '.png'.
- *
- * @return string Image URL, or a fixed unknown image.
- */
- public function get_image(){
- return APPLICATION::img("INVENTORY", $this->id);
- }
- }
- ?>
|