|
@@ -0,0 +1,246 @@
|
|
|
|
|
+ <?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();
|
|
|
|
|
+ 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)){
|
|
|
|
|
+ $artifact = new Artifact($r["id"]);
|
|
|
|
|
+ if (strlen($artifact->assigned_to) > 0){
|
|
|
|
|
+ $artifact->assigned_to = new Unit($artifact->assigned_to, false);
|
|
|
|
|
+ }
|
|
|
|
|
+ array_push($this->artifacts, $artifact);
|
|
|
|
|
+ }
|
|
|
|
|
+ $s = "
|
|
|
|
|
+ SELECT id
|
|
|
|
|
+ FROM filter
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ uid = '$UID' AND
|
|
|
|
|
+ page = 'ARTIFACTS';
|
|
|
|
|
+ ";
|
|
|
|
|
+ $q = $db->query($s);
|
|
|
|
|
+ while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
|
|
+ array_push($this->custom_filters, new Custom_Filter($r["id"]));
|
|
|
|
|
+ }
|
|
|
|
|
+ $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 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,
|
|
|
|
|
+ assigned_to
|
|
|
|
|
+ FROM artifact
|
|
|
|
|
+ WHERE uid = '$UID' AND (
|
|
|
|
|
+ $cond
|
|
|
|
|
+ )
|
|
|
|
|
+ ORDER BY slot, type, stars DESC, original_quality DESC, quality DESC, level;
|
|
|
|
|
+ ";
|
|
|
|
|
+ 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, " .
|
|
|
|
|
+ " assigned_to " .
|
|
|
|
|
+ "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 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;";
|
|
|
|
|
+ error_log($s);
|
|
|
|
|
+ return $s;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+?>
|