view = PATH::VIEW . "monsters.php"; $this->parse_filters(); $s_mon = $this->build_query(); $q_mon = $db->query($s_mon); while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){ array_push($this->monsters, new Unit($r_mon["id"])); } $this->title = "Monsters - SWDB"; $this->description = "Owned monsters"; $this->canonical = URL::BASE . "monsters/"; } /** * Parses the request looking for the selected filters, validates them * and adds them to the $filters array. */ private function parse_filters(){ $this->filters = FILTER::MONSTER; if (isset($_GET["element"]) && APPLICATION::valid_id("ELEMENT_ID", strtoupper($_GET["element"]))){ $this->filters["ELEMENT"] = $_GET["element"]; } if (isset($_GET["name"]) && strlen($_GET["name"]) > 0){ $this->filters["NAME"] = SQLite3::escapeString($_GET["name"]); } if (isset($_GET["min_stars"]) && intval($_GET["min_stars"]) > 0 && intval($_GET["min_stars"]) <= 6){ $this->filters["MIN_STARS"] = $_GET["min_stars"]; } if (isset($_GET["max_stars"]) && intval($_GET["max_stars"]) > 0 && intval($_GET["max_stars"]) <= 6){ $this->filters["MAX_STARS"] = $_GET["max_stars"]; } if (isset($_GET["in_storage"]) && $_GET["in_storage"] == "on"){ $this->filters["IN_STORAGE"] = true; } else{ $this->filters["IN_STORAGE"] = false; } if (isset($_GET["without_runes"]) && $_GET["without_runes"] == "on"){ $this->filters["WITHOUT_RUNES"] = true; } return; } /** * Builds the query to the rune table using the selected or default * filters. * * @return string The query to be executed. * @global int Player ID. * @global resource Database connection. */ private function build_query(){ global $UID; global $db; $s = " SELECT unit.id AS id FROM unit, k_unit WHERE unit.uid = '$UID' AND unit.unit = k_unit.id AND stars >= " . $this->filters["MIN_STARS"] . " AND stars <= " . $this->filters["MAX_STARS"]; if (APPLICATION::valid_id("ELEMENT_ID", $this->filters["ELEMENT"])){ $s = $s . " AND unit IN (SELECT id FROM k_unit WHERE element = " . $this->filters["ELEMENT"] . ") "; } if ($this->filters["NAME"] != ""){ $s = $s . " AND unit IN (SELECT id FROM k_unit WHERE upper(name) LIKE '%" . strtoupper($this->filters["NAME"]) . "%') "; } if (!$this->filters["IN_STORAGE"]){ $s = $s . " AND building NOT IN (SELECT id FROM building WHERE building = " . BUILDING_ID::MONSTER_STORAGE . ") "; } if (!$this->filters["WITHOUT_RUNES"]){ $s = $s . " AND unit.id IN (SELECT DISTINCT assigned_to FROM rune) "; } $s = $s . " ORDER BY stars DESC, level DESC, element = " . ELEMENT_ID::FIRE ." DESC, element = " . ELEMENT_ID::WATER ." DESC, element = " . ELEMENT_ID::WIND ." DESC, element = " . ELEMENT_ID::LIGHT ." DESC, element = " . ELEMENT_ID::DARK ." DESC "; return $s; } } ?>