| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- /**
- * Inventory base entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- /**
- * An inventory base item.
- *
- * Represents an object from the table 'k_inventory'.
- *
- * @category Entity
- */
- class K_Inventory extends Entity{
- /**
- * @var int Item identifier.
- */
- public $id;
- /**
- * @var string Item name.
- */
- public $name;
- /**
- * @var string Item type name.
- */
- public $type;
- /**
- * @var string Item description.
- */
- public $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.
- * @global resource Database connection.
- */
- public function __construct($id, $type = null){
- global $db;
- $s = "
- SELECT
- k_inventory.id AS id,
- k_inventory.name AS name,
- k_inventory.description AS description,
- k_inventory_type.name AS type
- FROM
- k_inventory,
- k_inventory_type
- WHERE
- k_inventory.type = k_inventory_type.id AND
- k_inventory.id = $id
- ";
- if ($type != null){
- $s .= "AND k_inventory.type = $type";
- }
- $q = $db->query($s);
- $r = $q->fetchArray(SQLITE3_ASSOC);
- $this->type = $r["type"];
- $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);
- }
- }
- ?>
|