Guild_Page.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Guild 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 . "Guild.php");
  13. require_once(PATH::ENTITY . "Guild_Skill_Group.php");
  14. /**
  15. * Guild page model.
  16. *
  17. * @category Page
  18. */
  19. class Guild_Page extends Page{
  20. /**
  21. * @var bool Indicates if the player is in a guild.
  22. */
  23. private $in_guild = false;
  24. /**
  25. * @var Guild Player guild.
  26. */
  27. private $guild;
  28. /**
  29. * @var Guild_Skill_Group[] List of Guild skill groups.
  30. */
  31. private $skill_groups = [];
  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("guild.php");
  41. $this->set_canonical("player/" . get_context()->get_player()->get_id() . "/guild/");
  42. $this->add_css("guild.css");
  43. $statement = get_context()->get_db()->prepare("
  44. SELECT id
  45. FROM guild
  46. WHERE id = (SELECT guild FROM guild_member WHERE member = :player);
  47. ");
  48. $statement->bindValue(":player", get_context()->get_player()->get_id(), SQLITE3_TEXT);
  49. $result_set = $statement->execute();
  50. $result = $result_set->fetchArray(SQLITE3_ASSOC);
  51. if ($result){
  52. $this->in_guild = true;
  53. $this->guild = new Guild($result["id"]);
  54. $this->set_title($this->guild->get_name());
  55. $this->set_description($this->guild->get_name() . " Guild");
  56. $statement = get_context()->get_db()->prepare("SELECT id FROM guild_skill_group ORDER BY id;");
  57. $skill_result_set = $statement->execute();
  58. while ($result = $skill_result_set->fetchArray(SQLITE3_ASSOC)){
  59. array_push($this->skill_groups, new Guild_Skill_Group($result["id"]));
  60. }
  61. }
  62. else{
  63. $this->in_guild = false;
  64. $this->set_title("Guild");
  65. $this->set_description("The player is not in a guild");
  66. }
  67. $this->set_code(200);
  68. $this->set_message("OK");
  69. }
  70. /**
  71. * Checks if the player is in a guild.
  72. *
  73. * @return bool True if the player is in a guild, false if not.
  74. */
  75. public function in_guild(){
  76. return $this->in_guild;
  77. }
  78. /**
  79. * Retrieves the guild.
  80. *
  81. * @return Guild Selected guild
  82. */
  83. public function get_guild(){
  84. return $this->guild;
  85. }
  86. /**
  87. * Retrieves the guild skil groups.
  88. *
  89. * @return Guild_Skill_Group[] Guild skill groups
  90. */
  91. public function get_skill_groups(){
  92. return $this->skill_groups;
  93. }
  94. }