K_Building.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. $s =
  45. "SELECT " .
  46. " id, " .
  47. " name, " .
  48. " description " .
  49. "FROM k_building " .
  50. "WHERE id = '$id'; ";
  51. $q = $db->query($s);
  52. $r = $q->fetchArray(SQLITE3_ASSOC);
  53. if ($r){
  54. $this->id = $r["id"];
  55. $this->name = HTML::e($r["name"]);
  56. $this->description = HTML::e($r["description"]);
  57. }
  58. }
  59. /**
  60. * Gets the path to the building image. The image must be in the
  61. * img/building/ directory, and its name must be the monster id,
  62. * padded with '0' to 4 digites, and the extension must be '.png'.
  63. *
  64. * @return string Image URL, or a fixed unknown image.
  65. */
  66. public function get_image(){
  67. return APPLICATION::img("BUILDING", $this->id);
  68. }
  69. }
  70. ?>