| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?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";
- }
- $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->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);
- }
- }
- ?>
|