Inventory.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Inventory base entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ENTITY . "Entity.php");
  12. /**
  13. * An in-game existing item.
  14. *
  15. * Represents an object that exist in the game.
  16. *
  17. * @category Entity
  18. */
  19. class Inventory extends Entity{
  20. /**
  21. * @var int Item identifier.
  22. */
  23. private $id;
  24. /**
  25. * @var string Item name.
  26. */
  27. private $name;
  28. /**
  29. * @var string Item type.
  30. */
  31. private $type;
  32. /**
  33. * @var string Item description.
  34. */
  35. private $description;
  36. /**
  37. * Constructor.
  38. *
  39. * Searches the database and retrieves the information about the
  40. * building, populating it and it's items.
  41. *
  42. * @param int $id Item identifier.
  43. * @param int $type Item type identifier. Optional, will try to guess if null.
  44. */
  45. public function __construct($id, $type = null){
  46. $s = "
  47. SELECT
  48. inventory.id AS id,
  49. inventory.name AS name,
  50. inventory.description AS description,
  51. inventory_type.name AS type
  52. FROM
  53. inventory,
  54. inventory_type
  55. WHERE
  56. inventory.type = inventory_type.id AND
  57. inventory.id = :id
  58. ";
  59. if ($type != null){
  60. $s .= "AND inventory.type = :type";
  61. }
  62. $statement = get_context()->get_db()->prepare($s);
  63. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  64. $statement->bindValue(':type', $type, SQLITE3_TEXT);
  65. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  66. if ($r){
  67. $this->type = $r["type"];
  68. $this->id = $r["id"];
  69. $this->name = HTML::e($r["name"]);
  70. $this->description = HTML::e($r["description"]);
  71. }
  72. }
  73. /**
  74. * Retrieves the owned item identifier.
  75. *
  76. * @return int Item ID.
  77. */
  78. public function get_id(){
  79. return $this->id;
  80. }
  81. /**
  82. * Retrieves the item name.
  83. *
  84. * @return string Item name.
  85. */
  86. public function get_name(){
  87. return $this->name;
  88. }
  89. /**
  90. * Retrieves the item type.
  91. *
  92. * @return int Item type.
  93. */
  94. public function get_type(){
  95. return $this->type;
  96. }
  97. /**
  98. * Retrieves the item description.
  99. *
  100. * @return string Item description.
  101. */
  102. public function get_description(){
  103. return $this->description;
  104. }
  105. /**
  106. * Gets the path to the item image.
  107. *
  108. * @return string Image URL, or a fixed unknown image.
  109. */
  110. public function get_image(){
  111. return APPLICATION::img("INVENTORY", $this->id);
  112. }
  113. }