Teams_Page.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "Team.php");
  4. /**
  5. * Monster list page.
  6. */
  7. class Teams_Page extends Page{
  8. /**
  9. * Array of @{see Team}s.
  10. */
  11. public $teams = [];
  12. /**
  13. * The filters the page can handle.
  14. */
  15. public $filters;
  16. /**
  17. * List of all units for team creation
  18. */
  19. public $units = [];
  20. /**
  21. * Constructor.
  22. *
  23. * Retrieves the data and initializes the variables.
  24. *
  25. * @param SQLite3 $db Connection to the database.
  26. */
  27. public function __construct($db){
  28. global $path;
  29. global $root;
  30. global $UID;
  31. parent::__construct($db);
  32. $this->view = $path["view"] . "teams.php";
  33. $this->parse_filters();
  34. $s = $this->build_query();
  35. $q = $this->db->query($s);
  36. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  37. array_push($this->teams, new Team($db, $r["id"]));
  38. }
  39. $s = "
  40. SELECT id
  41. FROM unit
  42. WHERE unit.uid = '$UID';
  43. ";
  44. $q = $this->db->query($s);
  45. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  46. array_push($this->units, new Unit($this->db, $r["id"], false));
  47. }
  48. $this->title = "Teams - SWDB";
  49. $this->description = "Teams";
  50. $this->canonical = $root . "teams/";
  51. }
  52. /**
  53. * Parses the request looking for the selected filters, validates them
  54. * and adds them to the $filters array.
  55. */
  56. private function parse_filters(){
  57. global $FILTER_TEAM;
  58. global $AREA_TYPE;
  59. $this->filters = $FILTER_TEAM;
  60. if (isset($_GET["area"]) && in_array($_GET["area"], $AREA_TYPE)){
  61. $this->filters["area"] = $_GET["area"];
  62. }
  63. if (isset($_GET["name"]) && strlen($_GET["name"]) > 0){
  64. $this->filters["name"] = SQLite3::escapeString($_GET["name"]);
  65. }
  66. return;
  67. }
  68. /**
  69. * Builds the query to the rune table using the selected or default
  70. * filters.
  71. *
  72. * @return The query to be executed.
  73. */
  74. private function build_query(){
  75. global $ELEMENT;
  76. global $UID;
  77. $s = "
  78. SELECT id
  79. FROM team
  80. WHERE uid = '$UID'
  81. ";
  82. if (in_array($this->filters["area"], $ELEMENT)){
  83. $s = $s . " AND area = '" . strtoupper($this->filters["area"]) . "') ";
  84. }
  85. if ($this->filters["name"] != ""){
  86. $s = $s . " AND upper(name) LIKE '%" . strtoupper($this->filters["name"]) . "%' ";
  87. }
  88. return $s;
  89. }
  90. }
  91. ?>