| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- require_once($path["page"] . "Page.php");
- require_once($path["entity"] . "Rune.php");
- require_once($path["entity"] . "Unit.php");
- /**
- * Rune list page.
- */
- class Runes_Page extends Page{
- /**
- * Array of @{see Rune}s.
- * NOTE: In this case, the monster member is not the id, but a monster
- * instance.
- */
- public $runes = [];
- /**
- * The filters the page can handle.
- */
- public $filters = [
- "type" => [],
- "main" => [],
- "sub" => [],
- "slot" => [],
- "min_quality" => 0,
- "max_quality" => 4,
- "min_original_quality" => 0,
- "max_original_quality" => 4,
- "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.
- *
- * @param SQLite3 $db Connection to the database.
- */
- public function __construct($db){
- global $path;
- global $root;
- parent::__construct($db);
- $this->view = $path["view"] . "runes.php";
- $this->parse_filters();
- $s = $this->build_query();
- error_log($s);
- $q = $this->db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $rune = new Rune($db, $r["id"]);
- if (strlen($rune->assigned_to) > 0){
- $rune->assigned_to = new Unit($this->db, $rune->assigned_to, false);
- //$rune->assigned_to = null;
- }
- array_push($this->runes, $rune);
- }
- $this->title = "Runes - SWDB";
- $this->description = "Rune inventory";
- $this->canonical = $root . "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"], strtoupper(SQLite3::escapeString($type)));
- }
- }
- if (isset($_GET["main"])){
- $mains = $_GET["main"];
- foreach ($mains as $main){
- array_push($this->filters["main"], strtoupper(SQLite3::escapeString($main)));
- }
- }
- if (isset($_GET["sub"])){
- $subs = $_GET["sub"];
- foreach ($subs as $sub){
- array_push($this->filters["sub"], strtoupper(SQLite3::escapeString($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"]) >= 0 && intval($_GET["min_quality"]) < 5){
- $this->filters["min_quality"] = $_GET["min_quality"];
- }
- if (isset($_GET["max_quality"]) && intval($_GET["max_quality"]) >= 0 && intval($_GET["max_quality"]) < 5){
- $this->filters["max_quality"] = $_GET["max_quality"];
- }
- if (isset($_GET["min_original_quality"]) && intval($_GET["min_original_quality"]) >= 0 && intval($_GET["min_original_quality"]) < 5){
- $this->filters["min_original_quality"] = $_GET["min_original_quality"];
- }
- if (isset($_GET["max_original_quality"]) && intval($_GET["max_original_quality"]) >= 0 && intval($_GET["max_original_quality"]) < 5){
- $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"] == "SLOT" || $_GET["group"] == "TYPE")){
- $this->filters["group"] = $_GET["group"];
- }
- return;
- }
- /**
- * Builds the query to the rune table using the selected or default
- * filters.
- *
- * @return The query to be executed.
- */
- private function build_query(){
- $s =
- "SELECT " .
- " id, " .
- " assigned_to " .
- "FROM rune " .
- "WHERE " .
- " 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["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 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 monster WHERE in_storage = 0)) ";
- break;
- case 4:
- $s = $s . " AND assigned_to IN (SELECT DISTINCT id FROM monster WHERE in_storage = 0) ";
- break;
- }
- $s = $s . " ORDER BY ";
- if ($this->filters["group"] == "TYPE"){
- $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, main_stat;";
- }
- return $s;
- }
- }
- ?>
|