| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * Team list page file.
- *
- * Provides a class with all the properties and methods to display the page.
- *
- * @category Page
- */
- /**
- * Require dependent files if not present.
- */
- require_once(PATH::PAGE . "Page.php");
- require_once(PATH::ENTITY . "Team.php");
- /**
- * Team list page model.
- *
- * @category Page
- */
- class Teams_Page extends Page{
- /**
- * @var \Team[] Teams to show.
- */
- public $teams = [];
- /**
- * @var \Unit[] List of all units for team creation.
- */
- public $units = [];
- /**
- * Constructor.
- *
- * Retrieves the data and initializes the variables.
- *
- * @global int Player ID.
- * @global resource Database connection.
- */
- public function __construct(){
- global $UID;
- global $db;
- $this->view = PATH::VIEW . "teams.php";
- $this->parse_filters();
- $s = $this->build_query();
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->teams, new Team($r["id"]));
- }
- $statement = $db->prepare("
- SELECT id
- FROM unit
- WHERE unit.uid = :uid;
- ");
- $statement->bindValue(':uid', $UID, SQLITE3_INTEGER);
- $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(){
- global $UID;
- $s = "
- SELECT id
- FROM team
- WHERE uid = '$UID'
- 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;
- }
- }
- ?>
|