| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- require_once($path["page"] . "Page.php");
- require_once($path["entity"] . "Monster.php");
- require_once($path["entity"] . "Rune.php");
- /**
- * Upgradeable runes report page.
- */
- class Report_Runeupgrade_Page extends Page{
- /**
- * Filtrs the eport can handle.
- */
- public $filters = [
- "min_stars" => 5,
- "max_stars" => 6,
- "in_storage" => true,
- ];
- /**
- * List of available upgrades. Can be described as:
- * $upgrades = [
- * [
- * monster (Monster),
- * upgrade = [
- * [
- * rune (Rune),
- * alternative = [(Rune)]
- * ]
- * ]
- * ]
- * ]
- */
- public $upgrades = [];
- /**
- * 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"] . "report_runeupgrade.php";
- $this->parse_filters();
- $s = $this->build_query();
- $q = $this->db->query($s);
- $prev_monster = "";
- $prev_rune = "";
- $upgrade = null;
- $rupgrade = null;
- $rune_i = 0; // DEBUG
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- if ($r["monster"] != $prev_monster){
- if ($prev_rune != ""){
- array_push($upgrade["upgrade"], $rupgrade);
- }
- if ($prev_monster != ""){
- array_push($this->upgrades, $upgrade);
- }
- $prev_monster = $r["monster"];
- $prev_rune = "";
- $upgrade = [
- "monster" => new Monster($this->db, $r["monster"]),
- "upgrade" => [],
- ];
- $rupgrade = [
- "rune" => new Rune($this->db, $r["id"]),
- "alternative" => [],
- ];
- }
- if ($r["id"] != $prev_rune){
- if ($prev_rune != ""){
- array_push($upgrade["upgrade"], $rupgrade);
- }
- $prev_rune = $r["id"];
- $rupgrade = [
- "rune" => new Rune($this->db, $r["id"]),
- "alternative" => [],
- ];
- }
- array_push($rupgrade["alternative"], new Rune($this->db, $r["alternative"]));
- $rune_i ++;
- }
- // Last entries
- array_push($upgrade["upgrade"], $rupgrade);
- array_push($this->upgrades, $upgrade);
- $this->title = "Replaceable runes - SWDB";
- $this->description = "Find equiped runes that can be substituted for better ones.";
- $this->canonical = $root . "report/runeupgrade/";
- }
- /**
- * Parses the filters passed in the request and sets $filters.
- * Filters must be in $_GET, nd the available ones are max_stars (1-6),
- * min_stars (1-6) and in_storage (on/off).
- */
- private function parse_filters(){
- 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["in_storage"]) && $_GET["in_storage"] != "on"){
- $this->filters["in_storage"] = false;
- }
- return;
- }
- /**
- * Builds the query for the page, using the providded or default filters.
- *
- * @return The query to be executed.
- */
- private function build_query(){
- $s =
- " SELECT " .
- " monster.id AS monster, " .
- " rune.id AS id, " .
- " rune_alt.id AS alternative " .
- "FROM " .
- " rune, " .
- " rune rune_alt, " .
- " monster " .
- "WHERE " .
- " monster.id = rune.assigned_to AND " .
- " monster.stars >= " . $this->filters["min_stars"] . " AND " .
- " monster.stars <= " . $this->filters["max_stars"] . " AND " .
- " rune.assigned_to IS NOT NULL AND " .
- " rune_alt.assigned_to IS NULL AND " .
- " rune.type = rune_alt.type AND " .
- " rune.slot = rune_alt.slot AND " .
- " rune.main_stat = rune_alt.main_stat AND " .
- " ( " .
- " rune_alt.stars > rune.stars OR " .
- " ( " .
- " rune_alt.stars = rune.stars AND " .
- " rune_alt.original_quality > rune.original_quality" .
- " ) " .
- " ) ";
- if (!$this->filters["in_storage"]){
- $s = $s . " AND monster.in_storage = 0 ";
- }
- $s = $s .
- "ORDER BY " .
- " monster.stars DESC, " .
- " monster.level DESC, " .
- " monster.id, " .
- " rune.slot, " .
- " id, " .
- " rune_alt.stars, " .
- " rune_alt.original_quality, " .
- " rune_alt.main_stat_value;";
- return $s;
- }
- }
- ?>
|