Teams_Page.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * Constructor.
  18. *
  19. * Retrieves the data and initializes the variables.
  20. *
  21. * @param SQLite3 $db Connection to the database.
  22. */
  23. public function __construct($db){
  24. global $path;
  25. global $root;
  26. parent::__construct($db);
  27. $this->view = $path["view"] . "teams.php";
  28. $this->parse_filters();
  29. $s = $this->build_query();
  30. $q = $this->db->query($s);
  31. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  32. array_push($this->teams, new Team($db, $r["id"]));
  33. }
  34. $this->title = "Teams - SWDB";
  35. $this->description = "Teams";
  36. $this->canonical = $root . "teams/";
  37. }
  38. /**
  39. * Parses the request looking for the selected filters, validates them
  40. * and adds them to the $filters array.
  41. */
  42. private function parse_filters(){
  43. global $FILTER_TEAM;
  44. global $AREA_TYPE;
  45. $this->filters = $FILTER_TEAM;
  46. if (isset($_GET["area"]) && in_array($_GET["area"], $AREA_TYPE)){
  47. $this->filters["area"] = $_GET["area"];
  48. }
  49. if (isset($_GET["name"]) && strlen($_GET["name"]) > 0){
  50. $this->filters["name"] = SQLite3::escapeString($_GET["name"]);
  51. }
  52. return;
  53. }
  54. /**
  55. * Builds the query to the rune table using the selected or default
  56. * filters.
  57. *
  58. * @return The query to be executed.
  59. */
  60. private function build_query(){
  61. global $ELEMENT;
  62. global $UID;
  63. $s = "
  64. SELECT id
  65. FROM team
  66. WHERE uid = '$UID'
  67. ";
  68. if (in_array($this->filters["area"], $ELEMENT)){
  69. $s = $s . " AND area = '" . strtoupper($this->filters["area"]) . "') ";
  70. }
  71. if ($this->filters["name"] != ""){
  72. $s = $s . " AND upper(name) LIKE '%" . strtoupper($this->filters["name"]) . "%' ";
  73. }
  74. return $s;
  75. }
  76. }
  77. ?>