[], "MAIN" => [], "SUB" => [], "SLOT" => [], "MIN_QUALITY" => QUALITY_ID::NORMAL, "MAX_QUALITY" => QUALITY_ID::LEGEND, "MIN_ORIGINAL_QUALITY" => QUALITY_ID::NORMAL, "MAX_ORIGINAL_QUALITY" => QUALITY_ID::LEGEND, "MIN_STARS" => 1, "MAX_STARS" => 6, "MIN_LEVEL" => 0, "MAX_LEVEL" => 15, "MIN_EFFICIENCY" => 0, "MAX_EFFICIENCY" => 100, "MIN_MAX_EFFICIENCY" => 0, "MAX_MAX_EFFICIENCY" => 100, "ASSIGNED" => 1, "GROUP" => "SLOT" ]; /** * 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 . "runes.php"; $this->parse_filters(); $s = $this->build_query(); $this->filters["GROUP"] = 1; $q = $db->query($s); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ $rune = new Rune($r["id"]); if ($r["unit"]){ $rune->unit = new Unit($r["unit"], false); } array_push($this->runes, $rune); } $this->title = "Runes - SWDB"; $this->description = "Rune inventory"; $this->canonical = URL::BASE . "runes/"; } /** * Parses the request looking for the selected filters, validates them * and adds them to the $filters array. */ private function parse_filters(){ if (isset($_GET["type"])){ $types = $_GET["type"]; foreach ($types as $type){ array_push($this->filters["TYPE"], intval($type)); } } if (isset($_GET["main_stat"])){ $mains = $_GET["main_stat"]; foreach ($mains as $main){ array_push($this->filters["MAIN"], intval($main)); } } if (isset($_GET["sub_stat"])){ $subs = $_GET["sub_stat"]; foreach ($subs as $sub){ array_push($this->filters["SUB"], intval($sub)); } } if (isset($_GET["slot"])){ $slots = $_GET["slot"]; foreach ($slots as $slot){ if (intval($slot) >= 1 && intval($slot) < 7){ array_push($this->filters["SLOT"], intval($slot)); } } } if (isset($_GET["min_stars"]) && intval($_GET["min_stars"]) > 0 && intval($_GET["min_stars"]) < 7){ $this->filters["MIN_STARS"] = $_GET["min_stars"]; } if (isset($_GET["max_stars"]) && intval($_GET["max_stars"]) > 0 && intval($_GET["max_stars"]) < 7){ $this->filters["MAX_STARS"] = $_GET["max_stars"]; } if (isset($_GET["min_level"]) && intval($_GET["min_level"]) >= 0 && intval($_GET["min_level"]) <= 15){ $this->filters["MIN_LEVEL"] = $_GET["min_level"]; } if (isset($_GET["max_level"]) && intval($_GET["max_level"]) >= 0 && intval($_GET["max_level"]) <= 15){ $this->filters["MAX_LEVEL"] = $_GET["max_level"]; } if (isset($_GET["min_quality"]) && intval($_GET["min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["min_quality"]) <= QUALITY_ID::LEGEND){ $this->filters["MIN_QUALITY"] = $_GET["min_quality"]; } if (isset($_GET["max_quality"]) && intval($_GET["max_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["max_quality"]) <= QUALITY_ID::LEGEND){ $this->filters["MAX_QUALITY"] = $_GET["max_quality"]; } if (isset($_GET["min_original_quality"]) && intval($_GET["min_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["min_original_quality"]) <= QUALITY_ID::LEGEND){ $this->filters["MIN_ORIGINAL_QUALITY"] = $_GET["min_original_quality"]; } if (isset($_GET["max_original_quality"]) && intval($_GET["max_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["max_original_quality"]) <= QUALITY_ID::LEGEND){ $this->filters["MAX_ORIGINAL_QUALITY"] = $_GET["max_original_quality"]; } if (isset($_GET["min_efficiency"]) && intval($_GET["min_efficiency"]) >= 0 && intval($_GET["min_efficiency"]) <= 100){ $this->filters["MIN_EFFICIENCY"] = $_GET["min_efficiency"]; } if (isset($_GET["max_efficiency"]) && intval($_GET["max_efficiency"]) >= 0 && intval($_GET["max_efficiency"]) <= 100){ $this->filters["MAX_EFFICIENCY"] = $_GET["max_efficiency"]; } if (isset($_GET["min_max_efficiency"]) && intval($_GET["min_max_efficiency"]) >= 0 && intval($_GET["min_max_efficiency"]) <= 100){ $this->filters["MIN_MAX_EFFICIENCY"] = $_GET["min_max_efficiency"]; } if (isset($_GET["max_max_efficiency"]) && intval($_GET["max_max_efficiency"]) >= 0 && intval($_GET["max_max_efficiency"]) <= 100){ $this->filters["MAX_MAX_EFFICIENCY"] = $_GET["max_max_efficiency"]; } if (isset($_GET["assigned"]) && intval($_GET["assigned"]) >= 0 && intval($_GET["assigned"]) <= 4){ $this->filters["ASSIGNED"] = $_GET["assigned"]; } if (isset($_GET["group"]) && ($_GET["group"] == "1" || $_GET["group"] == "0")){ $this->filters["GROUP"] = $_GET["group"]; } } /** * Builds the query to the rune table using the selected or default * filters. * * @return string The query to be executed. * @global int Player ID. */ private function build_query(){ global $UID; global $MODE; $s = " SELECT id, ( SELECT DISTINCT unit FROM unit_rune WHERE rune = rune.id AND rta = $MODE ) AS unit FROM rune WHERE uid = '$UID' AND stars >= " . $this->filters["MIN_STARS"] . " AND stars <= " . $this->filters["MAX_STARS"] . " AND level >= " . $this->filters["MIN_LEVEL"] . " AND level <= " . $this->filters["MAX_LEVEL"] . " AND quality >= " . $this->filters["MIN_QUALITY"] . " AND quality <= " . $this->filters["MAX_QUALITY"] . " AND original_quality >= " . $this->filters["MIN_ORIGINAL_QUALITY"] . " AND original_quality <= " . $this->filters["MAX_ORIGINAL_QUALITY"] . " AND efficiency >= " . $this->filters["MIN_EFFICIENCY"] . " AND efficiency <= " . $this->filters["MAX_EFFICIENCY"] . " AND max_efficiency >= " . $this->filters["MIN_MAX_EFFICIENCY"] . " AND max_efficiency <= " . $this->filters["MAX_MAX_EFFICIENCY"] . " "; if (count($this->filters["MAIN"]) > 0){ $values = "("; foreach($this->filters["MAIN"] as $t){ $values = $values . "'$t', "; } $values = $values . "'DUMMY0') "; $s .= " AND id IN ( SELECT rune FROM rune_stat WHERE slot = " . RUNE_STAT_SLOT_ID::MAIN . " AND stat IN $values ) "; } if (count($this->filters["SUB"]) > 0){ $values = "("; foreach($this->filters["SUB"] as $t){ $values = $values . "'$t', "; } $values = $values . "'DUMMY0') "; $s .= " AND id IN ( SELECT rune FROM rune_stat WHERE slot != " . RUNE_STAT_SLOT_ID::MAIN . " AND stat IN $values ) "; } if (count($this->filters["TYPE"]) > 0){ $s = $s . " AND upper(type) IN ( "; foreach($this->filters["TYPE"] as $t){ $s = $s . "'$t', "; } $s = $s . "'DUMMY0') "; } if (count($this->filters["SLOT"]) > 0){ $s = $s . " AND slot IN ( "; foreach($this->filters["SLOT"] as $t){ $s = $s . "$t, "; } $s = $s . "-1) "; } switch ($this->filters["ASSIGNED"]){ case 1: $s = $s . " AND unit IS NOT NULL "; break; case 2: $s = $s . " AND unit IS NULL "; break; case 3: $s = $s . " AND (unit IS NULL OR unit IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ")) "; break; case 4: $s = $s . " AND unit IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ") "; break; } $s = $s . " ORDER BY "; if ($this->filters["GROUP"] == 1){ // 1: Type, 0: Slot $s = $s . " type, slot, stars DESC, original_quality DESC, quality DESC, level;"; } else{ $s = $s . " slot, type, stars DESC, original_quality DESC, quality DESC, level;"; } return $s; } } ?>