K_Inventory.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Inventory base entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. /**
  10. * Require dependent entities if not present.
  11. */
  12. require_once(PATH::ENTITY . "Entity.php");
  13. /**
  14. * An inventory base item.
  15. *
  16. * Represents an object from the table 'k_inventory'.
  17. *
  18. * @category Entity
  19. */
  20. class K_Inventory extends Entity{
  21. /**
  22. * @var int Item identifier.
  23. */
  24. public $id;
  25. /**
  26. * @var string Item name.
  27. */
  28. public $name;
  29. /**
  30. * @var string Item type name.
  31. */
  32. public $type;
  33. /**
  34. * @var string Item description.
  35. */
  36. public $description;
  37. /**
  38. * Constructor.
  39. *
  40. * Searches the database and retrieves the information about the
  41. * building, populating it and it's items.
  42. *
  43. * @param resource $db Connection to the database.
  44. * @param int $id Item identifier.
  45. * @param int $type Item type identifier. Optional, will try to guess if null.
  46. */
  47. public function __construct($db, $id, $type = null){
  48. parent::__construct($db);
  49. $s = "
  50. SELECT
  51. k_inventory.id AS id,
  52. k_inventory.name AS name,
  53. k_inventory.description AS description,
  54. k_inventory_type.name AS type
  55. FROM
  56. k_inventory,
  57. k_inventory_type
  58. WHERE
  59. k_inventory.type = k_inventory_type.id AND
  60. k_inventory.id = $id
  61. ";
  62. if ($type != null){
  63. $s .= "AND k_inventory.type = $type";
  64. }
  65. $q = $this->db->query($s);
  66. $r = $q->fetchArray(SQLITE3_ASSOC);
  67. $this->type = $r["type"];
  68. $this->amount = $r["amount"];
  69. $this->id = $r["id"];
  70. $this->name = HTML::e($r["name"]);
  71. $this->description = HTML::e($r["description"]);
  72. }
  73. /**
  74. * Gets the path to the item image. The image must be in the
  75. * img/content/inventory/ directory, and its name must be the item id,
  76. * padded with '0' to 9 digites, and the extension must be '.png'.
  77. *
  78. * @return string Image URL, or a fixed unknown image.
  79. */
  80. public function get_image(){
  81. return APPLICATION::img("INVENTORY", $this->id);
  82. }
  83. }
  84. ?>