Przeglądaj źródła

Added enchantment section

Iñigo Valentin 6 lat temu
rodzic
commit
7606fdf82e

+ 11 - 0
application/Constant.php

@@ -1965,6 +1965,17 @@
             "ASSIGNED" => 1
         ];
 
+        /**
+         * Default values for the enchantment filters.
+         */
+        const ENCHANTMENT = [
+            "TYPE" => [],
+            "RUNE" => [],
+            "STAT" => [],
+            "MIN_QUALITY" => QUALITY_ID::NORMAL,
+            "MAX_QUALITY" => QUALITY_ID::LEGEND,
+        ];
+
         /**
          * Default values for the run filters.
          */

+ 4 - 0
application/Controller.php

@@ -195,6 +195,10 @@
                     require_once(PATH::PAGE . "Runes_Page.php");
                     $page = new Runes_Page();
                 }
+                elseif (strtoupper($pars[0]) == "ENCHANTMENTS"){
+                    require_once(PATH::PAGE . "Enchantments_Page.php");
+                    $page = new Enchantments_Page();
+                }
                 elseif (strtoupper($pars[0]) == "ARTIFACTS"){
                     require_once(PATH::PAGE . "Artifacts_Page.php");
                     $page = new Artifacts_Page();

+ 289 - 0
application/page/Enchantments_Page.php

@@ -0,0 +1,289 @@
+ <?php
+ 
+    /**
+     * Enchantment 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 . "Rune_Craft.php");
+
+    /**
+     * Enchantment list page model.
+     *
+     * @category Page
+     */
+    class Enchantments_Page extends Page{
+
+        /**
+         * @var \Rune_Craft[] Owned enchantment gems.
+         */
+        public $gems = [];
+
+        /**
+         * @var \Rune_Craft[] Owned enchantment grindstones.
+         */
+        public $grindstones = [];
+
+        /**
+         * @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 . "enchantments.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)){
+                $enchantment = new Rune_Craft($r["id"]);
+                //if ($enchantment->gem == true){
+                //   array_push($this->gems, $enchantment);
+                //}
+                //else{
+                    array_push($this->grindstones, $enchantment);
+                //}
+            }
+            $s = "
+              SELECT id
+              FROM filter
+              WHERE
+                uid = '$UID' AND
+                page = 'ENCHANTMENTS';
+            ";
+            $q = $db->query($s);
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->custom_filters, new Custom_Filter($r["id"]));
+            }
+            $this->title = "Enchantments - SWDB";
+            $this->description = "Enchantment inventory";
+            $this->canonical = URL::BASE . "enchantments/";
+        }
+
+        /**
+         * Parses the request looking for the selected filters, validates them
+         * and adds them to the $filters array.
+         */
+        private function parse_filters(){
+            $this->filters = FILTER::ENCHANTMENT;
+            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["stat"])){
+                $stats = $_GET["stat"];
+                foreach ($stats as $stat){
+                    array_push($this->filters["STAT"], intval($stat));
+                }
+            }
+            if (isset($_GET["rune"])){
+                $runes = $_GET["rune"];
+                foreach ($runes as $rune){
+                    array_push($this->filters["RUNE"], intval($rune));
+                }
+            }
+            if (isset($_GET["type"])){
+                $types = $_GET["type"];
+                foreach ($types as $type){
+                    array_push($this->filters["TYPE"], $type);
+                }
+            }
+            // TODO
+            /*
+            if (isset($_GET["archetype"])){
+                $archetypes = $_GET["archetype"];
+                foreach ($archetypes as $archetype){
+                    array_push($this->filters["ARCHETYPE"], intval($archetype));
+                }
+            }
+            
+            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_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
+              FROM rune_craft
+              WHERE uid = '$UID' AND (
+                $cond
+              )
+              ORDER BY type, rune DESC, quality DESC;
+            ";
+            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
+              FROM rune_craft
+              WHERE
+                uid = '$UID' AND
+                quality >= " . $this->filters["MIN_QUALITY"] . " AND
+                quality <= " . $this->filters["MAX_QUALITY"] . "
+            ";
+            if (count($this->filters["STAT"]) > 0){
+                $s = $s . " AND stat IN ( ";
+                foreach($this->filters["STAT"] as $t){
+                    $s = $s . "$t, ";
+                }
+                $s = $s . "-1) ";
+            }
+            if (count($this->filters["RUNE"]) > 0){
+                $s = $s . " AND (rune IN ( ";
+                foreach($this->filters["RUNE"] as $t){
+                    $s = $s . "'$t', ";
+                }
+                $s = $s . "'DUMMY0') ";
+                if (in_array('0', $this->filters["RUNE"])){
+                    // Include inmemorials
+                    $s .= " OR type in (3, 4)) ";
+                }
+                else{
+                    $s .= ") ";
+                }
+            }
+            error_log( print_r($this->filters["TYPE"], TRUE) );
+            if (count($this->filters["TYPE"]) == 1){
+                // Only one selectd, it's either gems or grindstones
+                if (in_array("GEM", $this->filters["TYPE"])){
+                    $s .= " AND type IN (1, 3, 5) "; // Gems.
+                }
+                else{
+                    $s .= " AND type IN (2, 4, 6) "; // Grindstones.
+                }
+            }
+            $s = $s . "
+              ORDER BY
+                type = 3 DESC,  -- Inmemorial Grindstone
+                type = 4 DESC,  -- Inmemorial Gem
+                rune,
+                type,
+                quality DESC,
+                stat
+            ";
+            /*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;
+        }
+    }
+?>

+ 129 - 0
application/view/enchantments.php

@@ -0,0 +1,129 @@
+<?php
+    /**
+     * Artifacts view.
+     *
+     * Contains the view layout and ome code to present the data.
+     *
+     * @category View
+     * @property_read Artifacts_Page $page The page model.
+     */
+?>
+<!DOCTYPE html>
+<html lang='en'>
+    <head>
+        <meta content='text/html; charset=utf-8' http-equiv='content-type'/>
+        <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'/>
+        <title><?=$page->title?></title>
+        <link rel='shortcut icon' href='<?=$page->favicon?>'/>
+        <!-- CSS files -->
+        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
+        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>enchantments.css'/>
+        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>filters.css'/>
+        <!-- Meta tags -->
+        <link rel='canonical' href='<?=$page->canonical?>'/>
+        <link rel='author' href='<?=$page->author?>'/>
+        <link rel='publisher' href='<?=$page->author?>'/>
+        <meta name='description' content='<?=$page->description?>'/>
+        <meta property='og:title' content='<?=$page->title?>'/>
+        <meta property='og:url' content='<?=$page->canonical?>'/>
+        <meta property='og:description' content='<?=$page->description?>'/>
+        <meta property='og:image' content='<?=$page->icon?>'/>
+        <meta property='og:site_name' content='<?=$page->name?>'/>
+        <meta property='og:type' content='website'/>
+        <meta property='og:locale' content='en'/>
+        <meta name='twitter:card' content='summary'/>
+        <meta name='twitter:title' content='<?=$page->title?>'/>
+        <meta name='twitter:description' content='<?=$page->description?>'/>
+        <meta name='twitter:image' content='<?=$page->icon?>'/>
+        <meta name='twitter:url' content='<?=$page->canonical?>'/>
+        <meta name='robots' content='index follow'/>
+        <script>
+
+            /**
+             * Shows or hiddes the filters panel.
+             */
+            function toggleFilters(){
+                var content = document.getElementById('filters_content');
+                var slid = document.getElementById('filters_slid');
+                if (content.style.maxHeight != '55em'){
+                    content.style.maxHeight = '55em';
+                    slid.style.transform = 'rotate(90deg)';
+                }
+                else{
+                    content.style.maxHeight = '0px';
+                    slid.style.transform = 'rotate(0deg)';
+                }
+            };
+        </script>
+    </head>
+    <body>
+<?php
+        include __DIR__ . "/inc/header.php";
+?>
+        <section class='filters'>
+            <h2 id='filters_title' onClick='toggleFilters();'>
+                <img id='filters_slid' id='filters_slid' alt=' ' src='<?=URL::IMG["ICON"]?>slid.png'/>
+                Artifact filters
+            </h2>
+            <article id='filters_content'>
+<?php
+                $filters = $page->filters;
+                $custom_filters = $page->custom_filters;
+                include __DIR__ . "/inc/filter_enchantments.php";
+?>
+            </article>
+
+        </section> <!-- #filters -->
+<?php
+            $prev_group = "";
+            $group = "";
+            $group_title = "";
+            $group_image = "";
+            foreach ($page->grindstones as $grindstone){
+                //$group = $grindstone->rune->id . "-" . $grindstone->gem . "-" . $grindstone->inmemorial;
+                $group = $grindstone->rune->id . "-" . $grindstone->inmemorial;
+                if ($prev_group != $group){
+                    if ($grindstone->inmemorial == 1){
+                        $group_title = "Inmemorial";
+                        $group_image = URL::IMG["ICON"] . "star.png";
+                    }
+                    else{
+                        $group_title = $grindstone->rune->name;
+                        $group_image = URL::IMG["RUNE"] . str_pad($grindstone->rune->id, 2, '0', STR_PAD_LEFT) . ".png";
+                    }
+                    if ($prev_group == ""){
+?>
+                        <section class='list'>
+<?php
+                    }
+                    else{
+?>
+                            </article>
+                        </section>
+                        <section class='list'>
+<?php
+                    }
+                    $prev_group = $group;
+?>
+                    <h2>
+                        <img class='group_image_<?=$group?>' alt='<?=$group_title?>' src='<?=$group_image?>'>
+                        <span>
+                            <?=$group_title?>
+                        </span>
+                    </h2>
+                    <article>
+<?php
+                }
+?>
+                <?=HTML::craft_panel($grindstone)?>
+<?php
+            }
+?>
+            </article> <!-- Close last group -->
+        </section>
+
+<?php
+        include __DIR__ . "/inc/footer.php";
+?>
+    </body>
+</html>

+ 161 - 0
application/view/inc/filter_enchantments.php

@@ -0,0 +1,161 @@
+<?php
+    /**
+     * Artifact filter view.
+     *
+     * To be included from the artifact view.
+     *
+     * @category View
+     * @property_read mixed[] $filters Selected filters.
+     * @property_read int $page Player ID.
+     */
+
+    if (count($custom_filters) > 0){
+?>
+        <script>
+            /**
+             * Changes the filter description.
+             *
+             * @param id Filter id.
+             */
+            function customFilterDescription(id){
+                switch (id){
+<?php
+                    foreach($custom_filters AS $filter){
+?>
+                        case '<?=$filter->id?>':
+                            document.getElementById("custom_filter_description").style.display = 'block';
+                            document.getElementById("custom_filter_description").innerHTML = '<?=$filter->description?>';
+                            break;
+<?php
+                    }
+?>
+                }
+            }
+        </script>
+        <form action='/<?=$UID?>/enchantments/' method='get' id='custom_filter_artifacts' class='custom_filter'>
+            <span class='custom_filter_title'>Custom filters:</span>
+            <select name='custom_filter' onChange='customFilterDescription(this.value);' onload='customFilterDescription("<?=filter_input(INPUT_GET, 'custom_filter')?>");'>
+                <option> </option>
+<?php
+                 foreach($custom_filters AS $filter){
+                    if (filter_input(INPUT_GET, 'custom_filter') == $filter->id){
+                        $selected = "selected='selected'";
+                    }
+                    else{
+                        $selected = "";
+                    }
+?>
+                    <option value='<?=$filter->id?>' <?=$selected?>><?=$filter->name?></option>
+<?php
+                 }
+?>
+            </select>
+            <input type='submit' value='Apply'/>
+            <p id='custom_filter_description'> </p>
+            <script>
+                customFilterDescription("<?=filter_input(INPUT_GET, 'custom_filter')?>");
+            </script>
+        </form>
+<?php
+    }
+?>
+<form action='/<?=$UID?>/enchantments/' method='get' id='filter_artifacts' class='filter'>
+    <div class='custom_filters'>
+    <table>
+        <tr>
+            <td class='filter'>
+                <span>Type:</span>
+                <select multiple name='type[]' id='filter_type'>
+<?php
+                    $selected = "";
+                    if (in_array("GRI", $filters["TYPE"])){
+                        $selected = "selected='selected'";
+                    }
+?>
+                    <option value='GRI' <?=$selected?>>Grindstone</option>
+<?php
+                    $selected = "";
+                    if (in_array("GEM", $filters["TYPE"])){
+                        $selected = "selected='selected'";
+                    }
+?>
+                    <option value='GEM' <?=$selected?>>Gem</option>
+                </select>
+            </td>
+            <td class='filter' colspan='2'>
+                <span>Quality:</span>
+<?php
+                $selected = Array("", "", "", "", "");
+                $selected[$filters["MIN_QUALITY"] - 1] = "selected";
+?>
+                <select name='min_quality' id='filter_quality_min'>
+                    <option value='<?=QUALITY_ID::NORMAL?>' <?=$selected[0]?>>Normal</option>
+                    <option value='<?=QUALITY_ID::MAGIC?>' <?=$selected[1]?>>Magic</option>
+                    <option value='<?=QUALITY_ID::RARE?>' <?=$selected[2]?>>Rare</option>
+                    <option value='<?=QUALITY_ID::HERO?>' <?=$selected[3]?>>Hero</option>
+                    <option value='<?=QUALITY_ID::LEGEND?>' <?=$selected[4]?>>Legend</option>
+                </select>
+                -
+<?php
+                $selected = Array("", "", "", "", "");
+                $selected[$filters["MAX_QUALITY"] - 1] = "selected";
+?>
+                <select name='max_quality' id='filter_quality_max'>
+                    <option value='<?=QUALITY_ID::NORMAL?>' <?=$selected[0]?>>Normal</option>
+                    <option value='<?=QUALITY_ID::MAGIC?>' <?=$selected[1]?>>Magic</option>
+                    <option value='<?=QUALITY_ID::RARE?>' <?=$selected[2]?>>Rare</option>
+                    <option value='<?=QUALITY_ID::HERO?>' <?=$selected[3]?>>Hero</option>
+                    <option value='<?=QUALITY_ID::LEGEND?>' <?=$selected[4]?>>Legend</option>
+                </select>
+            </td>
+        </tr>
+        <tr>
+            <td class='filter'>
+                <span>Rune:</span>
+                <select multiple name='rune[]' id='filter_rune'>
+<?php
+                    $selected = "";
+                    if (in_array(0, $filters["RUNE"])){
+                        $selected = "selected='selected'";
+                    }
+?>
+                    <option value='0' <?=$selected?>>Inmemorial</option>
+<?php
+                    $reflect = new ReflectionClass("RUNE_SET_ID");
+                    foreach($reflect->getConstants() as $name => $id){
+                        $selected = "";
+                        if (in_array($id, $filters["RUNE"])){
+                            $selected = "selected='selected'";
+                        }
+?>
+                        <option value='<?=$id?>' <?=$selected?>><?=$name?></option>
+<?php
+                    }
+?>
+                </select>
+            </td>
+            <td class='filter'>
+                <span>Stat:</span>
+                <select multiple name='stat[]' id='filter_stat'>
+<?php
+                    $reflect = new ReflectionClass("RUNE_STAT_ID");
+                    foreach($reflect->getConstants() as $name => $id){
+                        $selected = "";
+                        if (in_array($id, $filters["STAT"])){
+                            $selected = "selected='selected'";
+                        }
+                        $name_format = ucwords(str_replace("_P", "%", $name));
+?>
+                        <option value='<?=$id?>' <?=$selected?>><?=$name_format?></option>
+<?php
+                    }
+?>
+                </select>
+            </td>
+        </tr>
+    </table>
+    <div id='filter_apply'>
+        <input type='submit' value='Apply'/>
+    </div>
+    </div>
+</form>

+ 3 - 0
application/view/inc/header.php

@@ -33,6 +33,9 @@
             <a href='/<?=$UID?>/runes/'>
                 Runes
             </a>
+            <a href='/<?=$UID?>/enchantments/'>
+                Enchantments
+            </a>
             <a href='/<?=$UID?>/artifacts/'>
                 Artifacts
             </a>

+ 19 - 0
public/css/enchantments.css

@@ -0,0 +1,19 @@
+section.filters td.filter select#filter_type{
+    height: 2.5em;
+    overflow: hidden;
+}
+section.filters td.filter select#filter_rune{
+    height: 26em;
+    overflow: hidden;
+}
+section.filters td.filter select#filter_stat{
+    height: 13em;
+    overflow: hidden;
+}
+section h2 img, span{
+    display: inline-block;
+    vertical-align: middle;
+}
+section h2 img{
+    height: 1.5em;
+}