| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- require_once($path["page"] . "Page.php");
- require_once($path["entity"] . "Monster.php");
- /**
- * Monster list page.
- */
- class Monsters_Page extends Page{
- /**
- * Array of @{see Monsters}s.
- */
- public $monsters = [];
- public $filters = [
- "element" => "",
- "name" => "",
- "min_stars" => 1,
- "max_stars" => 6,
- "in_storage" => true,
- "without_runes" => true
- ];
- /**
- * 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"] . "monsters.php";
- $this->parse_filters();
- $s_mon = $this->build_query();
- $q_mon = $this->db->query($s_mon);
- while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
- array_push($this->monsters, new Monster($db, $r_mon["id"]));
- }
- $this->title = "Monsters - SWDB";
- $this->description = "Owned monsters";
- $this->canonical = $root . "monsters/";
- }
- private function parse_filters(){
- $f_element = strtoupper($_GET["element"]);
- if ($f_element == "FIRE" || $f_element == "WATER" || $f_element == "WIND" || $f_element == "LIGHT" || $f_element == "DARK"){
- $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"]) < 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;
- }
- if (isset($_GET["without_runes"]) && $_GET["without_runes"] != "on"){
- $this->filters["without_runes"] = false;
- }
- return;
- }
- private function build_query(){
- $s = "SELECT monster.id AS id FROM monster, k_monster WHERE monster.monster = k_monster.id AND stars >= " . $this->filters["min_stars"] . " AND stars <= " . $this->filters["max_stars"];
- if (strlen($this->filters["element"]) > 0){
- $s = $s . " AND monster IN (SELECT id FROM k_monster WHERE upper(element) = '" . strtoupper($this->filters["element"]) . "') ";
- }
- if ($this->filters["name"] != ""){
- $s = $s . " AND monster IN (SELECT id FROM k_monster WHERE upper(name) LIKE '%" . strtoupper($this->filters["name"]) . "%') ";
- }
- if (!$this->filters["in_storage"]){
- $s = $s . " AND in_storage = 0 ";
- }
- if (!$this->filters["without_runes"]){
- $s = $s . " AND id IN (SELECT DISTINCT monster FROM monster_rune) ";
- }
- $s = $s . " ORDER BY stars DESC, level DESC, element;";
- return $s;
- }
- }
- ?>
|