Buildable.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Buildable entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ENTITY . "Entity.php");
  12. /**
  13. * Buildable.
  14. *
  15. * Represents any of the available buildings in the game.
  16. *
  17. * Buildings that can be built and leveled up are not considered buildables, but {@link Decorative}.
  18. * It does not represent a building owned by the player.
  19. *
  20. * @category Entity
  21. */
  22. class Buildable extends Entity{
  23. /**
  24. * @var int Buildable ID.
  25. */
  26. private $id;
  27. /**
  28. * @var string Buildable name.
  29. */
  30. private $name;
  31. /**
  32. * @var string Buildable description.
  33. */
  34. private $description;
  35. /**
  36. * Constructor.
  37. *
  38. * Searches the database and retrieves the information about the
  39. * building, populating it and it's items.
  40. *
  41. * @param int $id Buildable identifier.
  42. */
  43. public function __construct($id){
  44. $statement = get_context()->get_db()->prepare("
  45. SELECT
  46. id,
  47. name,
  48. description
  49. FROM buildable
  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. * Retrieves the buildable identifier.
  62. *
  63. * @return int Buildable ID.
  64. */
  65. public function get_id(){
  66. return $this->id;
  67. }
  68. /**
  69. * Retrieves the buildable name.
  70. *
  71. * @return string Buildable name.
  72. */
  73. public function get_name(){
  74. return $this->name;
  75. }
  76. /**
  77. * Retrieves the buildable description.
  78. *
  79. * @return string Buildable description.
  80. */
  81. public function get_description(){
  82. return $this->description;
  83. }
  84. /**
  85. * Gets the path to the building image.
  86. *
  87. * @return string Image URL, or a fixed unknown image.
  88. */
  89. public function get_image(){
  90. return APPLICATION::img("BUILDING", $this->id);
  91. }
  92. }