[], "stage" => [], "difficulty" => [], "win_lose" => 0, "helper" => false ]; /** * Constructor. * * Retrieves the data and initializes the variables. * * @param SQLite3 $db Connection to the database. */ public function __construct($db){ global $path; global $root; parent::__construct($db); $this->view = $path["view"] . "runs.php"; $this->parse_filters(); $s = $this->build_query(); $q = $this->db->query($s); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->runs, new Run($db, $r["id"])); } $this->title = "Runs - SWDB"; $this->description = "Run logs"; $this->canonical = $root . "runs/"; } /** * Parses the request looking for the selected filters, validates them * and adds them to the $filters array. */ private function parse_filters(){ if (isset($_GET["area"])){ $areas = $_GET["area"]; foreach ($areas as $area){ array_push($this->filters["area"], intval($ara)); } } if (isset($_GET["stage"])){ $stages = $_GET["stage"]; foreach ($stages as $stage){ array_push($this->filters["stage"], intval($ara)); } } if (isset($_GET["difficulty"])){ $difficultys = $_GET["difficulty"]; foreach ($difficultys as $difficulty){ array_push($this->filters["difficulty"], intval($ara)); } } if (isset($_GET["win_lose"]) && intval($_GET["win_lose"]) >= 0 && intval($_GET["win_lose"]) <= 2){ $this->filters["win_lose"] = $_GET["win_lose"]; } if (isset($_GET["helper"]) && $_GET["elper"] == "on"){ $this->filters["helper"] = true; } else{ $this->filters["helper"] = false; } return; } /** * Builds the query to the run table using the selected or default * filters. * * @return The query to be executed. */ private function build_query(){ $s = " SELECT id FROM run WHERE 1 = 1 "; if (count($this->filters["area"]) > 0){ $s = $s . " AND area IN ( "; foreach($this->filters["area"] as $t){ $s = $s . "'$t', "; } $s = $s . "'DUMMY0') "; } if (count($this->filters["stage"]) > 0){ $s = $s . " AND stage IN ( "; foreach($this->filters["stage"] as $t){ $s = $s . "'$t', "; } $s = $s . "'DUMMY0') "; } if (count($this->filters["difficulty"]) > 0){ $s = $s . " AND difficulty IN ( "; foreach($this->filters["difficulty"] as $t){ $s = $s . "'$t', "; } $s = $s . "'DUMMY0') "; } switch ($this->filters["win_lose"]){ case 1: $s = $s . " AND win = 1 "; break; case 2: $s = $s . " AND win = 0 "; break; } return $s; } } ?>