Runes_Page.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "Rune.php");
  4. require_once($path["entity"] . "Unit.php");
  5. /**
  6. * Rune list page.
  7. */
  8. class Runes_Page extends Page{
  9. /**
  10. * Array of @{see Rune}s.
  11. * NOTE: In this case, the monster member is not the id, but a monster
  12. * instance.
  13. */
  14. public $runes = [];
  15. /**
  16. * The filters the page can handle.
  17. */
  18. public $filters = [
  19. "type" => [],
  20. "main" => [],
  21. "sub" => [],
  22. "slot" => [],
  23. "min_quality" => 0,
  24. "max_quality" => 4,
  25. "min_original_quality" => 0,
  26. "max_original_quality" => 4,
  27. "min_stars" => 1,
  28. "max_stars" => 6,
  29. "min_level" => 0,
  30. "max_level" => 15,
  31. "min_efficiency" => 0,
  32. "max_efficiency" => 100,
  33. "min_max_efficiency" => 0,
  34. "max_max_efficiency" => 100,
  35. "assigned" => 1,
  36. "group" => 0 // 0-> SLOT, 1->TYPE
  37. ];
  38. /**
  39. * Constructor.
  40. *
  41. * Retrieves the data and initializes the variables.
  42. *
  43. * @param SQLite3 $db Connection to the database.
  44. */
  45. public function __construct($db){
  46. global $path;
  47. global $root;
  48. parent::__construct($db);
  49. $this->view = $path["view"] . "runes.php";
  50. $this->parse_filters();
  51. $s = $this->build_query();
  52. $q = $this->db->query($s);
  53. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  54. $rune = new Rune($db, $r["id"]);
  55. if (strlen($rune->assigned_to) > 0){
  56. $rune->assigned_to = new Unit($this->db, $rune->assigned_to, false);
  57. }
  58. array_push($this->runes, $rune);
  59. }
  60. $this->title = "Runes - SWDB";
  61. $this->description = "Rune inventory";
  62. $this->canonical = $root . "runes/";
  63. }
  64. /**
  65. * Parses the request looking for the selected filters, validates them
  66. * and adds them to the $filters array.
  67. */
  68. private function parse_filters(){
  69. global $QUALITY;
  70. if (isset($_GET["type"])){
  71. $types = $_GET["type"];
  72. foreach ($types as $type){
  73. array_push($this->filters["type"], intval($type));
  74. }
  75. }
  76. if (isset($_GET["main"])){
  77. $mains = $_GET["main"];
  78. foreach ($mains as $main){
  79. array_push($this->filters["main"], intval($main));
  80. }
  81. }
  82. if (isset($_GET["sub"])){
  83. $subs = $_GET["sub"];
  84. foreach ($subs as $sub){
  85. array_push($this->filters["sub"], intval($sub));
  86. }
  87. }
  88. if (isset($_GET["slot"])){
  89. $slots = $_GET["slot"];
  90. foreach ($slots as $slot){
  91. if (intval($slot) >= 1 && intval($slot) < 7){
  92. array_push($this->filters["slot"], intval($slot));
  93. }
  94. }
  95. }
  96. if (isset($_GET["min_stars"]) && intval($_GET["min_stars"]) > 0 && intval($_GET["min_stars"]) < 7){
  97. $this->filters["min_stars"] = $_GET["min_stars"];
  98. }
  99. if (isset($_GET["max_stars"]) && intval($_GET["max_stars"]) > 0 && intval($_GET["max_stars"]) < 7){
  100. $this->filters["max_stars"] = $_GET["max_stars"];
  101. }
  102. if (isset($_GET["min_level"]) && intval($_GET["min_level"]) >= 0 && intval($_GET["min_level"]) <= 15){
  103. $this->filters["min_level"] = $_GET["min_level"];
  104. }
  105. if (isset($_GET["max_level"]) && intval($_GET["max_level"]) >= 0 && intval($_GET["max_level"]) <= 15){
  106. $this->filters["max_level"] = $_GET["max_level"];
  107. }
  108. if (isset($_GET["min_quality"]) && intval($_GET["min_quality"]) >= $QUALITY["NORMAL"] && intval($_GET["min_quality"]) <= $QUALITY["LEGEND"]){
  109. $this->filters["min_quality"] = $_GET["min_quality"];
  110. }
  111. if (isset($_GET["max_quality"]) && intval($_GET["max_quality"]) >= $QUALITY["NORMAL"] && intval($_GET["max_quality"]) <= $QUALITY["LEGEND"]){
  112. $this->filters["max_quality"] = $_GET["max_quality"];
  113. }
  114. if (isset($_GET["min_original_quality"]) && intval($_GET["min_original_quality"]) >= $QUALITY["NORMAL"] && intval($_GET["min_original_quality"]) <= $QUALITY["LEGEND"]){
  115. $this->filters["min_original_quality"] = $_GET["min_original_quality"];
  116. }
  117. if (isset($_GET["max_original_quality"]) && intval($_GET["max_original_quality"]) >= $QUALITY["NORMAL"] && intval($_GET["max_original_quality"]) <= $QUALITY["LEGEND"]){
  118. $this->filters["max_original_quality"] = $_GET["max_original_quality"];
  119. }
  120. if (isset($_GET["min_efficiency"]) && intval($_GET["min_efficiency"]) >= 0 && intval($_GET["min_efficiency"]) <= 100){
  121. $this->filters["min_efficiency"] = $_GET["min_efficiency"];
  122. }
  123. if (isset($_GET["max_efficiency"]) && intval($_GET["max_efficiency"]) >= 0 && intval($_GET["max_efficiency"]) <= 100){
  124. $this->filters["max_efficiency"] = $_GET["max_efficiency"];
  125. }
  126. if (isset($_GET["min_max_efficiency"]) && intval($_GET["min_max_efficiency"]) >= 0 && intval($_GET["min_max_efficiency"]) <= 100){
  127. $this->filters["min_max_efficiency"] = $_GET["min_max_efficiency"];
  128. }
  129. if (isset($_GET["max_max_efficiency"]) && intval($_GET["max_max_efficiency"]) >= 0 && intval($_GET["max_max_efficiency"]) <= 100){
  130. $this->filters["max_max_efficiency"] = $_GET["max_max_efficiency"];
  131. }
  132. if (isset($_GET["assigned"]) && intval($_GET["assigned"]) >= 0 && intval($_GET["assigned"]) <= 4){
  133. $this->filters["assigned"] = $_GET["assigned"];
  134. }
  135. if (isset($_GET["group"]) && ($_GET["group"] == "1" || $_GET["group"] == "0")){
  136. $this->filters["group"] = $_GET["group"];
  137. }
  138. return;
  139. }
  140. /**
  141. * Builds the query to the rune table using the selected or default
  142. * filters.
  143. *
  144. * @return The query to be executed.
  145. */
  146. private function build_query(){
  147. global $UID;
  148. $s =
  149. "SELECT " .
  150. " id, " .
  151. " assigned_to " .
  152. "FROM rune " .
  153. "WHERE " .
  154. " uid = '$UID' AND " .
  155. " stars >= " . $this->filters["min_stars"] . " AND " .
  156. " stars <= " . $this->filters["max_stars"] . " AND " .
  157. " level >= " . $this->filters["min_level"] . " AND " .
  158. " level <= " . $this->filters["max_level"] . " AND " .
  159. " quality >= " . $this->filters["min_quality"] . " AND " .
  160. " quality <= " . $this->filters["max_quality"] . " AND " .
  161. " original_quality >= " . $this->filters["min_original_quality"] . " AND " .
  162. " original_quality <= " . $this->filters["max_original_quality"] . " AND " .
  163. " efficiency >= " . $this->filters["min_efficiency"] . " AND " .
  164. " efficiency <= " . $this->filters["max_efficiency"] . " AND " .
  165. " max_efficiency >= " . $this->filters["min_max_efficiency"] . " AND " .
  166. " max_efficiency <= " . $this->filters["max_max_efficiency"] . " ";
  167. if (count($this->filters["type"]) > 0){
  168. $s = $s . " AND upper(type) IN ( ";
  169. foreach($this->filters["type"] as $t){
  170. $s = $s . "'$t', ";
  171. }
  172. $s = $s . "'DUMMY0') ";
  173. }
  174. if (count($this->filters["slot"]) > 0){
  175. $s = $s . " AND slot IN ( ";
  176. foreach($this->filters["slot"] as $t){
  177. $s = $s . "$t, ";
  178. }
  179. $s = $s . "-1) ";
  180. }
  181. switch ($this->filters["assigned"]){
  182. case 1:
  183. $s = $s . " AND assigned_to IS NOT NULL ";
  184. break;
  185. case 2:
  186. $s = $s . " AND assigned_to IS NULL ";
  187. break;
  188. case 3:
  189. // TODO
  190. //$s = $s . " AND (assigned_to IS NULL OR assigned_to IN (SELECT DISTINCT id FROM unit WHERE in_storage = 0)) ";
  191. break;
  192. case 4:
  193. //$s = $s . " AND assigned_to IN (SELECT DISTINCT id FROM unit WHERE in_storage = 0) ";
  194. break;
  195. }
  196. $s = $s . " ORDER BY ";
  197. if ($this->filters["group"] == 1){ // 1: Type, 0: Slot
  198. $s = $s . " type, slot, stars DESC, original_quality DESC, quality DESC, level;";
  199. }
  200. else{
  201. $s = $s . " slot, type, stars DESC, original_quality DESC, quality DESC, level, main_stat;";
  202. }
  203. return $s;
  204. }
  205. }
  206. ?>