K_Building.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Building key 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. * Building.
  15. *
  16. * Represents an object from the table 'k_building'.
  17. *
  18. * @category Entity
  19. */
  20. class K_Building extends Entity{
  21. /**
  22. * @var int Building identifier.
  23. */
  24. public $id;
  25. /**
  26. * @var string Building name.
  27. */
  28. public $name;
  29. /**
  30. * @var string Building description.
  31. */
  32. public $description;
  33. /**
  34. * Constructor.
  35. *
  36. * Searches the database and retrieves the information about the
  37. * building, populating it and it's items.
  38. *
  39. * @param int $id Building identifier.
  40. * @global resource Database connection.
  41. */
  42. public function __construct($id){
  43. global $db;
  44. $statement = $db->prepare("
  45. SELECT
  46. id,
  47. name,
  48. description
  49. FROM k_building
  50. WHERE id = :id;
  51. ");
  52. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  53. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  54. if ($r){
  55. $this->id = $r["id"];
  56. $this->name = HTML::e($r["name"]);
  57. $this->description = HTML::e($r["description"]);
  58. }
  59. }
  60. /**
  61. * Gets the path to the building image. The image must be in the
  62. * img/building/ directory, and its name must be the monster id,
  63. * padded with '0' to 4 digites, and the extension must be '.png'.
  64. *
  65. * @return string Image URL, or a fixed unknown image.
  66. */
  67. public function get_image(){
  68. return APPLICATION::img("BUILDING", $this->id);
  69. }
  70. }
  71. ?>