Buildings_Page.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Building list page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  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::PAGE . "Page.php");
  12. require_once(PATH::ENTITY . "Buildable.php");
  13. require_once(PATH::ENTITY . "Decorative.php");
  14. /**
  15. * Building list page model.
  16. *
  17. * @category Page
  18. */
  19. class Buildings_Page extends Page{
  20. /**
  21. * @var Buildable[] List of buildables to show.
  22. */
  23. private $buildables = [];
  24. /**
  25. * @var Decorative[] List of decoratives to show.
  26. */
  27. private $decoratives = [];
  28. /**
  29. * @var Decorative[] List of Guild Flags to show.
  30. */
  31. private $flags = [];
  32. /**
  33. * Constructor.
  34. *
  35. * Retrieves the data and initializes the variables.
  36. */
  37. public function __construct(){
  38. parent::__construct();
  39. $this->set_public(true);
  40. $this->set_view("buildings.php");
  41. $this->set_title("Buildings");
  42. $this->set_description("List of all buildings");
  43. $this->set_canonical("buildings/");
  44. $this->add_css("buildings.css");
  45. // Buildings
  46. $statement = get_context()->get_db()->prepare("SELECT id FROM buildable;");
  47. $result_set = $statement->execute();
  48. while ($result = $result_set->fetchArray(SQLITE3_ASSOC)){
  49. array_push($this->buildables, new Buildable($result["id"]));
  50. }
  51. // Decorations
  52. $statement = get_context()->get_db()->prepare("SELECT id FROM decorative WHERE area != :guild;");
  53. $statement->bindValue(":guild", EFFECT_AREA_ID::GUILD);
  54. $result_set = $statement->execute();
  55. while ($result = $result_set->fetchArray(SQLITE3_ASSOC)){
  56. array_push($this->decoratives, new Decorative($result["id"]));
  57. }
  58. // Flags
  59. $statement = get_context()->get_db()->prepare("SELECT id FROM decorative WHERE area = :guild;");
  60. $statement->bindValue(":guild", EFFECT_AREA_ID::GUILD);
  61. $result_set = $statement->execute();
  62. while ($result = $result_set->fetchArray(SQLITE3_ASSOC)){
  63. array_push($this->flags, new Decorative($result["id"]));
  64. }
  65. $this->set_code(200);
  66. $this->set_message("OK");
  67. }
  68. /**
  69. * Retrieves the buildings to display
  70. *
  71. * @return Buildable[] Selected buildables.
  72. */
  73. public function get_buildables(){
  74. return $this->buildables;
  75. }
  76. /**
  77. * Retrieves the decorations to display, excluding Guild Flags
  78. *
  79. * @return Decorative[] Selected decoratives.
  80. */
  81. public function get_decoratives(){
  82. return $this->decoratives;
  83. }
  84. /**
  85. * Retrieves the Guild Flags to display
  86. *
  87. * @return Decorative[] Selected flags.
  88. */
  89. public function get_flags(){
  90. return $this->flags;
  91. }
  92. }