Buildable.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  22. * @var int Buildable identifier.
  23. */
  24. public $id;
  25. /**
  26. * @var string Buildable name.
  27. */
  28. public $name;
  29. /**
  30. * @var string Buildable 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 Buildable identifier.
  40. */
  41. public function __construct($id){
  42. $statement = get_context()->get_db()->prepare("
  43. SELECT
  44. id,
  45. name,
  46. description
  47. FROM buildable
  48. WHERE id = :id;
  49. ");
  50. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  51. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  52. if ($r){
  53. $this->id = $r["id"];
  54. $this->name = HTML::e($r["name"]);
  55. $this->description = HTML::e($r["description"]);
  56. }
  57. }
  58. /**
  59. * Gets the path to the building image. The image must be in the
  60. * img/building/ directory, and its name must be the monster id,
  61. * padded with '0' to 4 digites, and the extension must be '.png'.
  62. *
  63. * @return string Image URL, or a fixed unknown image.
  64. */
  65. public function get_image(){
  66. return APPLICATION::img("BUILDING", $this->id);
  67. }
  68. }
  69. ?>