K_Inventory.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 int $id Item identifier.
  44. * @param int $type Item type identifier. Optional, will try to guess if null.
  45. * @global resource Database connection.
  46. */
  47. public function __construct($id, $type = null){
  48. global $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. $statement = $db->prepare($s);
  66. $statement->bindValue(':id', $id, SQLITE3_INTEGER);
  67. $statement->bindValue(':type', $type, SQLITE3_INTEGER);
  68. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  69. if ($r){
  70. $this->type = $r["type"];
  71. $this->id = $r["id"];
  72. $this->name = HTML::e($r["name"]);
  73. $this->description = HTML::e($r["description"]);
  74. }
  75. }
  76. /**
  77. * Gets the path to the item image. The image must be in the
  78. * img/content/inventory/ directory, and its name must be the item id,
  79. * padded with '0' to 9 digites, and the extension must be '.png'.
  80. *
  81. * @return string Image URL, or a fixed unknown image.
  82. */
  83. public function get_image(){
  84. return APPLICATION::img("INVENTORY", $this->id);
  85. }
  86. }
  87. ?>