Inventory.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Inventory 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. require_once(PATH::ENTITY . "K_Unit.php");
  14. /**
  15. * An inventory item.
  16. *
  17. * Represents an object from the table 'inventory'.
  18. *
  19. * @category Entity
  20. */
  21. class Inventory extends Entity{
  22. /**
  23. * @var int Owner identifier.
  24. */
  25. public $uid;
  26. /**
  27. * @var int|K_Unit Item identifier. If its a monster piece, a K_Unit entity.
  28. */
  29. public $id;
  30. /**
  31. * @var string Item name.
  32. */
  33. public $name;
  34. /**
  35. * @var string Item type name.
  36. */
  37. public $type;
  38. /**
  39. * @var int Item owned amount.
  40. */
  41. public $amount;
  42. /**
  43. * @var bool Indicates if the item are monster pieces.
  44. */
  45. public $is_monster_pices;
  46. /**
  47. * Constructor.
  48. *
  49. * Searches the database and retrieves the information about the
  50. * building, populating it and it's items.
  51. *
  52. * @param resource $db Connection to the database.
  53. * @param int $id Item identifier.
  54. * @param int $type Item type identifier. Optional, will try to guess if null.
  55. */
  56. public function __construct($db, $id, $type = null){
  57. parent::__construct($db);
  58. $s = "
  59. SELECT
  60. inventory.id AS id,
  61. k_inventory.name AS name,
  62. k_inventory.description AS description,
  63. inventory.type AS type_ref,
  64. k_inventory_type.name AS type,
  65. inventory.amount AS amount
  66. FROM
  67. inventory,
  68. k_inventory,
  69. k_inventory_type
  70. WHERE
  71. inventory.type = k_inventory_type.id AND
  72. inventory.id = k_inventory.id AND
  73. inventory.type = k_inventory.type AND
  74. inventory.id = $id
  75. ";
  76. if ($type != null){
  77. $s .= "AND inventory.type = $type";
  78. }
  79. $q = $this->db->query($s);
  80. $r = $q->fetchArray(SQLITE3_ASSOC);
  81. $this->type = $r["type"];
  82. $this->amount = $r["amount"];
  83. if ($r["type"] == INVENTORY_TYPE_ID::GUILD_MONSTER_PIECE || $r["type"] == INVENTORY_TYPE_ID::MONSTER_PIECE){
  84. $this->is_monster_pices = true;
  85. $this->id = new K_Unit($this->db, $r["id"]);
  86. $this->name = HTML::e($this->id->title) . " Pieces";
  87. $this->description = HTML::e($this->id->title) . " Pieces";
  88. }
  89. else{
  90. $this->is_monster_pices = false;
  91. $this->id = $r["id"];
  92. $this->name = HTML::e($r["name"]);
  93. $this->description = HTML::e($r["description"]);
  94. }
  95. }
  96. /**
  97. * Gets the path to the item image. The image must be in the
  98. * img/content/inventory/ directory, and its name must be the item id,
  99. * padded with '0' to 9 digites, and the extension must be '.png'.
  100. *
  101. * @return string Image URL, or a fixed unknown image.
  102. */
  103. public function get_image(){
  104. return APPLICATION::img("INVENTORY", $this->id);
  105. }
  106. }
  107. ?>