view = PATH::VIEW . "teams.php"; $this->parse_filters(); $s = $this->build_query(); $q = get_context()->get_db()->query($s); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->teams, new Team($r["id"])); } $statement = get_context()->get_db()->prepare(" SELECT id FROM unit WHERE player = :player; "); $statement->bindValue(':player', get_context()->get_player()->get_id(), SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->units, new Unit($r["id"], false)); } $this->title = "Teams - SWDB"; $this->description = "Teams"; $this->canonical = URL::BASE . "teams/"; } /** * Parses the request looking for the selected filters, validates them * and adds them to the $filters array. */ private function parse_filters(){ $this->filters = FILTER::TEAM; if (isset($_GET["area"]) && APPLICATION::valid_id("AREA_TYPE_ID", $_GET["area"])){ $this->filters["AREA"] = $_GET["area"]; } if (isset($_GET["name"]) && strlen($_GET["name"]) > 0){ $this->filters["NAME"] = SQLite3::escapeString($_GET["name"]); } return; } /** * Builds the query to the rune table using the selected or default * filters. * * @return string The query to be executed. */ private function build_query(){ $s = " SELECT id FROM team WHERE player = '" . get_context()->get_player()->get_id() . "' ORDER BY area_type, area "; if (APPLICATION::valid_id("AREA_ID", $this->filters["AREA"])){ $s = $s . " AND area = '" . strtoupper($this->filters["AREA"]) . "') "; } if ($this->filters["NAME"] != ""){ $s = $s . " AND upper(name) LIKE '%" . strtoupper($this->filters["NAME"]) . "%' "; } return $s; } } ?>