Buildable.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Buildable 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. * Buildable.
  15. *
  16. * Represents an object from the table 'buildable'.
  17. *
  18. * @category Entity
  19. */
  20. class Buildable extends Entity{
  21. private $id;
  22. private $name;
  23. private $description;
  24. /**
  25. * Constructor.
  26. *
  27. * Searches the database and retrieves the information about the
  28. * building, populating it and it's items.
  29. *
  30. * @param int $id Buildable identifier.
  31. */
  32. public function __construct($id){
  33. $statement = get_context()->get_db()->prepare("
  34. SELECT
  35. id,
  36. name,
  37. description
  38. FROM buildable
  39. WHERE id = :id;
  40. ");
  41. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  42. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  43. if ($r){
  44. $this->id = $r["id"];
  45. $this->name = HTML::e($r["name"]);
  46. $this->description = HTML::e($r["description"]);
  47. }
  48. }
  49. /**
  50. * Retrieves the buildable identifier.
  51. *
  52. * @return int Buildable ID.
  53. */
  54. public function get_id(){
  55. return $this->id;
  56. }
  57. /**
  58. * Retrieves the buildable name.
  59. *
  60. * @return string Buildable name.
  61. */
  62. public function get_name(){
  63. return $this->name;
  64. }
  65. /**
  66. * Retrieves the buildable description.
  67. *
  68. * @return string Buildable description.
  69. */
  70. public function get_description(){
  71. return $this->description;
  72. }
  73. /**
  74. * Gets the path to the building image.
  75. *
  76. * @return string Image URL, or a fixed unknown image.
  77. */
  78. public function get_image(){
  79. return APPLICATION::img("BUILDING", $this->id);
  80. }
  81. }
  82. ?>