Inventory.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 in -game existing item.
  15. *
  16. * Represents an object from the table 'inventory'.
  17. *
  18. * @category Entity
  19. */
  20. class Inventory extends Entity{
  21. /**
  22. * @var int Item identifier.
  23. */
  24. private $id;
  25. /**
  26. * @var string Item name.
  27. */
  28. private $name;
  29. /**
  30. * @var string Item type name.
  31. */
  32. private $type;
  33. /**
  34. * @var string Item description.
  35. */
  36. private $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 int $id Item identifier.
  44. * @param int $type Item type identifier. Optional, will try to guess if null.
  45. */
  46. public function __construct($id, $type = null){
  47. $s = "
  48. SELECT
  49. inventory.id AS id,
  50. inventory.name AS name,
  51. inventory.description AS description,
  52. inventory_type.name AS type
  53. FROM
  54. inventory,
  55. inventory_type
  56. WHERE
  57. inventory.type = inventory_type.id AND
  58. inventory.id = :id
  59. ";
  60. if ($type != null){
  61. $s .= "AND inventory.type = :type";
  62. }
  63. $statement = get_context()->get_db()->prepare($s);
  64. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  65. $statement->bindValue(':type', $type, SQLITE3_TEXT);
  66. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  67. if ($r){
  68. $this->type = $r["type"];
  69. $this->id = $r["id"];
  70. $this->name = HTML::e($r["name"]);
  71. $this->description = HTML::e($r["description"]);
  72. }
  73. }
  74. /**
  75. * Retrieves the owned item identifier.
  76. *
  77. * @return int Item ID.
  78. */
  79. public function get_id(){
  80. return $this->id;
  81. }
  82. /**
  83. * Retrieves the item name.
  84. *
  85. * @return string Item name.
  86. */
  87. public function get_name(){
  88. return $this->name;
  89. }
  90. /**
  91. * Retrieves the item type.
  92. *
  93. * @return int Item type.
  94. */
  95. public function get_type(){
  96. return $this->type;
  97. }
  98. /**
  99. * Retrieves the item description.
  100. *
  101. * @return string Item description.
  102. */
  103. public function get_description(){
  104. return $this->description;
  105. }
  106. /**
  107. * Gets the path to the item image.
  108. *
  109. * @return string Image URL, or a fixed unknown image.
  110. */
  111. public function get_image(){
  112. return APPLICATION::img("INVENTORY", $this->id);
  113. }
  114. }
  115. ?>