Guild_Page.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $this->view = PATH::VIEW . "guild.php";
  39. $statement = get_context()->get_db()->prepare("
  40. SELECT id
  41. FROM guild
  42. WHERE id = (SELECT guild FROM guild_member WHERE member = :player);
  43. ");
  44. $statement->bindValue(":player", get_context()->get_player()->get_id(), SQLITE3_TEXT);
  45. $result_set = $statement->execute();
  46. $result = $result_set->fetchArray(SQLITE3_ASSOC);
  47. if ($result){
  48. $this->in_guild = true;
  49. $this->guild = new Guild($result["id"]);
  50. $this->title = $this->guild->get_name() . " - SWDB";
  51. $this->description = $this->guild->get_name() . " Guild details";
  52. $statement = get_context()->get_db()->prepare("SELECT id FROM guild_skill_group ORDER BY id;");
  53. $skill_result_set = $statement->execute();
  54. while ($result = $skill_result_set->fetchArray(SQLITE3_ASSOC)){
  55. array_push($this->skill_groups, new Guild_Skill_Group($result["id"]));
  56. }
  57. }
  58. else{
  59. $this->in_guild = false;
  60. $this->title = "Guild - SWDB";
  61. $this->description = "No guild";
  62. }
  63. $this->canonical = URL::BASE . "guild/";
  64. }
  65. /**
  66. * Checks if the player is in a guild.
  67. *
  68. * @return bool True if the player is in a guild, false if not.
  69. */
  70. public function in_guild(){
  71. return $this->in_guild;
  72. }
  73. /**
  74. * Retrieves the guild.
  75. *
  76. * @return Guild Selected guild
  77. */
  78. public function get_guild(){
  79. return $this->guild;
  80. }
  81. /**
  82. * Retrieves the guild skil groups.
  83. *
  84. * @return Guild_Skill_Group[] Guild skill groups
  85. */
  86. public function get_skill_groups(){
  87. return $this->skill_groups;
  88. }
  89. }