K_Building.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 resource $db Connection to the database.
  40. * @param int $id Building identifier.
  41. */
  42. public function __construct($db, $id){
  43. parent::__construct($db);
  44. $s =
  45. "SELECT " .
  46. " id, " .
  47. " name, " .
  48. " description " .
  49. "FROM k_building " .
  50. "WHERE id = '$id'; ";
  51. $q = $this->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. ?>