view = PATH::VIEW . "enchantments.php"; $this->parse_filters(); if (!isset($_GET["custom_filter"])){ $s = $this->build_query(); } else{ $s = $this->build_custom_query($_GET["custom_filter"]); } $q = $db->query($s); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ $enchantment = new Enchantment($r["id"]); //if ($enchantment->gem == true){ // array_push($this->gems, $enchantment); //} //else{ array_push($this->grindstones, $enchantment); //} } $s = " SELECT id FROM filter WHERE uid = '$UID' AND page = 'ENCHANTMENTS'; "; $q = $db->query($s); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->custom_filters, new Custom_Filter($r["id"])); } $this->title = "Enchantments - SWDB"; $this->description = "Enchantment inventory"; $this->canonical = URL::BASE . "enchantments/"; } /** * Parses the request looking for the selected filters, validates them * and adds them to the $filters array. */ private function parse_filters(){ $this->filters = FILTER::ENCHANTMENT; 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["stat"])){ $stats = $_GET["stat"]; foreach ($stats as $stat){ array_push($this->filters["STAT"], intval($stat)); } } if (isset($_GET["rune"])){ $runes = $_GET["rune"]; foreach ($runes as $rune){ array_push($this->filters["RUNE"], intval($rune)); } } if (isset($_GET["type"])){ $types = $_GET["type"]; foreach ($types as $type){ array_push($this->filters["TYPE"], $type); } } // TODO /* if (isset($_GET["archetype"])){ $archetypes = $_GET["archetype"]; foreach ($archetypes as $archetype){ array_push($this->filters["ARCHETYPE"], intval($archetype)); } } 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_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["assigned"]) && intval($_GET["assigned"]) >= 0 && intval($_GET["assigned"]) <= 4){ $this->filters["ASSIGNED"] = $_GET["assigned"]; }*/ } /** * Builds the query to the artifact table using the a custom filter. * * @param int $filter Custom filter ID. * @return string The query to be executed. * @global int Player ID. * @global resource Database connection. */ private function build_custom_query($filter){ global $UID; global $db; $s = " SELECT condition FROM filter WHERE uid = '$UID' AND id = $filter; "; $q = $db->query($s); $r = $q->fetchArray(SQLITE3_ASSOC); $cond = $r["condition"]; $s = " SELECT id FROM enchantment WHERE uid = '$UID' AND ( $cond ) ORDER BY type, rune DESC, quality DESC; "; return $s; } /** * Builds the query to the artifact table using the selected or default * filters. * * @return string The query to be executed. * @global int Player ID. */ private function build_query(){ global $UID; $s = " SELECT id FROM enchantment WHERE uid = '$UID' AND quality >= " . $this->filters["MIN_QUALITY"] . " AND quality <= " . $this->filters["MAX_QUALITY"] . " "; if (count($this->filters["STAT"]) > 0){ $s = $s . " AND stat IN ( "; foreach($this->filters["STAT"] as $t){ $s = $s . "$t, "; } $s = $s . "-1) "; } if (count($this->filters["RUNE"]) > 0){ $s = $s . " AND (rune IN ( "; foreach($this->filters["RUNE"] as $t){ $s = $s . "'$t', "; } $s = $s . "'DUMMY0') "; if (in_array('0', $this->filters["RUNE"])){ // Include inmemorials $s .= " OR type in (3, 4)) "; } else{ $s .= ") "; } } if (count($this->filters["TYPE"]) == 1){ // Only one selectd, it's either gems or grindstones if (in_array("GEM", $this->filters["TYPE"])){ $s .= " AND type IN (1, 3, 5) "; // Gems. } else{ $s .= " AND type IN (2, 4, 6) "; // Grindstones. } } $s = $s . " ORDER BY type = 3 DESC, -- Inmemorial Grindstone type = 4 DESC, -- Inmemorial Gem rune, type, quality DESC, stat "; /*if (count($this->filters["MAIN"]) > 0){ $s = $s . " AND main_stat IN ( "; foreach($this->filters["MAIN"] as $t){ $s = $s . "$t, "; } $s = $s . "-1) "; } if (count($this->filters["ELEMENT"]) == 0 && count($this->filters["ARCHETYPE"]) == 0){ // No element/archetype conditions } elseif (count($this->filters["ELEMENT"]) > 0 && count($this->filters["ARCHETYPE"]) == 0){ // Only selected elements $s = $s . " AND attribute IN ( "; foreach($this->filters["ELEMENT"] as $t){ $s = $s . "$t, "; } $s = $s . "-1) "; } elseif (count($this->filters["ELEMENT"]) == 0 && count($this->filters["ARCHETYPE"]) > 0){ // Only selected types $s = $s . " AND archetype IN ( "; foreach($this->filters["ARCHETYPE"] as $t){ $s = $s . "$t, "; } $s = $s . "-1) "; } elseif (count($this->filters["ELEMENT"]) > 0 && count($this->filters["ARCHETYPE"]) > 0){ // Selected elements and selected types $s = $s . " AND (archetype IN ( "; foreach($this->filters["ARCHETYPE"] as $t){ $s = $s . "$t, "; } $s = $s . "-1) OR attribute IN ( "; foreach($this->filters["ELEMENT"] as $t){ $s = $s . "$t, "; } $s = $s . "-1)) "; } switch ($this->filters["ASSIGNED"]){ case 1: $s = $s . " AND assigned_to IS NOT NULL "; break; case 2: $s = $s . " AND assigned_to IS NULL "; break; case 3: $s = $s . " AND (assigned_to IS NULL OR assigned_to IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ")) "; break; case 4: $s = $s . " AND assigned_to IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ") "; break; } $s = $s . " ORDER BY type, attribute, archetype, level DESC, original_quality DESC;"; */ return $s; } } ?>