| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
-
- /**
- * Artifact list page file.
- *
- * Provides a class with all the properties and methods to display the page.
- *
- * @category Page
- */
- /**
- * Require dependent files if not present.
- */
- require_once(PATH::PAGE . "Page.php");
- require_once(PATH::ENTITY . "Custom_Filter.php");
- require_once(PATH::ENTITY . "Artifact.php");
- require_once(PATH::ENTITY . "Unit.php");
- /**
- * Artifact list page model.
- *
- * @category Page
- */
- class Artifacts_Page extends Page{
- /**
- * @var \Artifact[] Artiffacts to show.
- *
- * In this case, the monster member is not the id, but a monster
- * instance.
- */
- public $artifacts = [];
- /**
- * @var \Filter[] Custom filters for this page.
- */
- public $custom_filters = [];
- /**
- * 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 . "artifacts.php";
- $this->parse_filters();
- $s = $this->build_query();
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $artifact = new Artifact($r["id"]);
- if ($r["unit"]){
- $artifact->unit = new Unit($r["unit"], false);
- }
- array_push($this->artifacts, $artifact);
- }
-
- $this->title = "Artifacts - SWDB";
- $this->description = "Artifact inventory";
- $this->canonical = URL::BASE . "artifacts/";
- }
- /**
- * Parses the request looking for the selected filters, validates them
- * and adds them to the $filters array.
- */
- private function parse_filters(){
- $this->filters = FILTER::ARTIFACT;
- if (isset($_GET["element"])){
- $elements = $_GET["element"];
- foreach ($elements as $element){
- array_push($this->filters["ELEMENT"], intval($element));
- }
- }
- if (isset($_GET["archetype"])){
- $archetypes = $_GET["archetype"];
- foreach ($archetypes as $archetype){
- array_push($this->filters["ARCHETYPE"], intval($archetype));
- }
- }
- if (isset($_GET["main_stat"])){
- $mains = $_GET["main_stat"];
- foreach ($mains as $main){
- array_push($this->filters["MAIN"], intval($main));
- }
- }
- 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["assigned"]) && intval($_GET["assigned"]) >= 0 && intval($_GET["assigned"]) <= 4){
- $this->filters["ASSIGNED"] = $_GET["assigned"];
- }
- }
- /**
- * 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;
- global $MODE;
- $s = "
- SELECT
- id,
- (
- SELECT DISTINCT unit
- FROM unit_artifact
- WHERE
- artifact = artifact.id AND
- rta = $MODE
- ) AS unit
- FROM artifact
- WHERE
- uid = '$UID' 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){
- $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 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 type, attribute, archetype, level DESC, original_quality DESC;";
- return $s;
- }
- }
- ?>
|