| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- require_once($path["page"] . "Page.php");
- require_once($path["entity"] . "Run.php");
- /**
- * Run list page.
- */
- class Runs_Page extends Page{
- /**
- * Array of @{see Run}s.
- */
- public $runs = [];
- /**
- * The filters the page can handle.
- */
- public $filters = [
- "area" => [],
- "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;
- }
- }
- ?>
|