Enchantments_Page.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * Enchantment list page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  6. *
  7. * @category Page
  8. */
  9. /**
  10. * Require dependent files if not present.
  11. */
  12. require_once(PATH::PAGE . "Page.php");
  13. require_once(PATH::ENTITY . "Enchantment.php");
  14. /**
  15. * Enchantment list page model.
  16. *
  17. * @category Page
  18. */
  19. class Enchantments_Page extends Page{
  20. /**
  21. * @var \Enchantment[] Owned enchantment gems.
  22. */
  23. public $gems = [];
  24. /**
  25. * @var \Enchantment[] Owned enchantment grindstones.
  26. */
  27. public $grindstones = [];
  28. /**
  29. * Constructor.
  30. *
  31. * Retrieves the data and initializes the variables.
  32. *
  33. * @global resource Database connection.
  34. */
  35. public function __construct(){
  36. global $db;
  37. $this->view = PATH::VIEW . "enchantments.php";
  38. $this->parse_filters();
  39. $s = $this->build_query();
  40. $q = $db->query($s);
  41. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  42. $enchantment = new Enchantment($r["id"]);
  43. //if ($enchantment->gem == true){
  44. // array_push($this->gems, $enchantment);
  45. //}
  46. //else{
  47. array_push($this->grindstones, $enchantment);
  48. //}
  49. }
  50. $this->title = "Enchantments - SWDB";
  51. $this->description = "Enchantment inventory";
  52. $this->canonical = URL::BASE . "enchantments/";
  53. }
  54. /**
  55. * Parses the request looking for the selected filters, validates them
  56. * and adds them to the $filters array.
  57. */
  58. private function parse_filters(){
  59. $this->filters = FILTER::ENCHANTMENT;
  60. if (isset($_GET["min_quality"]) && intval($_GET["min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["min_quality"]) <= QUALITY_ID::LEGEND){
  61. $this->filters["MIN_QUALITY"] = $_GET["min_quality"];
  62. }
  63. if (isset($_GET["max_quality"]) && intval($_GET["max_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["max_quality"]) <= QUALITY_ID::LEGEND){
  64. $this->filters["MAX_QUALITY"] = $_GET["max_quality"];
  65. }
  66. if (isset($_GET["stat"])){
  67. $stats = $_GET["stat"];
  68. foreach ($stats as $stat){
  69. array_push($this->filters["STAT"], intval($stat));
  70. }
  71. }
  72. if (isset($_GET["rune"])){
  73. $runes = $_GET["rune"];
  74. foreach ($runes as $rune){
  75. array_push($this->filters["RUNE"], intval($rune));
  76. }
  77. }
  78. if (isset($_GET["type"])){
  79. $types = $_GET["type"];
  80. foreach ($types as $type){
  81. array_push($this->filters["TYPE"], $type);
  82. }
  83. }
  84. // TODO
  85. /*
  86. if (isset($_GET["archetype"])){
  87. $archetypes = $_GET["archetype"];
  88. foreach ($archetypes as $archetype){
  89. array_push($this->filters["ARCHETYPE"], intval($archetype));
  90. }
  91. }
  92. if (isset($_GET["min_level"]) && intval($_GET["min_level"]) >= 0 && intval($_GET["min_level"]) <= 15){
  93. $this->filters["MIN_LEVEL"] = $_GET["min_level"];
  94. }
  95. if (isset($_GET["max_level"]) && intval($_GET["max_level"]) >= 0 && intval($_GET["max_level"]) <= 15){
  96. $this->filters["MAX_LEVEL"] = $_GET["max_level"];
  97. }
  98. if (isset($_GET["min_original_quality"]) && intval($_GET["min_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["min_original_quality"]) <= QUALITY_ID::LEGEND){
  99. $this->filters["MIN_ORIGINAL_QUALITY"] = $_GET["min_original_quality"];
  100. }
  101. if (isset($_GET["max_original_quality"]) && intval($_GET["max_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["max_original_quality"]) <= QUALITY_ID::LEGEND){
  102. $this->filters["MAX_ORIGINAL_QUALITY"] = $_GET["max_original_quality"];
  103. }
  104. if (isset($_GET["assigned"]) && intval($_GET["assigned"]) >= 0 && intval($_GET["assigned"]) <= 4){
  105. $this->filters["ASSIGNED"] = $_GET["assigned"];
  106. }*/
  107. }
  108. /**
  109. * Builds the query to the artifact table using the selected or default
  110. * filters.
  111. *
  112. * @return string The query to be executed.
  113. * @global Player Currently selected player.
  114. */
  115. private function build_query(){
  116. global $PLAYER;
  117. $s = "
  118. SELECT id
  119. FROM data.enchantment
  120. WHERE
  121. player = '" . $PLAYER->id . "' AND
  122. quality >= " . $this->filters["MIN_QUALITY"] . " AND
  123. quality <= " . $this->filters["MAX_QUALITY"] . "
  124. ";
  125. if (count($this->filters["STAT"]) > 0){
  126. $s = $s . " AND stat IN ( ";
  127. foreach($this->filters["STAT"] as $t){
  128. $s = $s . "$t, ";
  129. }
  130. $s = $s . "-1) ";
  131. }
  132. if (count($this->filters["RUNE"]) > 0){
  133. $s = $s . " AND (rune IN ( ";
  134. foreach($this->filters["RUNE"] as $t){
  135. $s = $s . "'$t', ";
  136. }
  137. $s = $s . "'DUMMY0') ";
  138. if (in_array('0', $this->filters["RUNE"])){
  139. // Include inmemorials
  140. $s .= " OR type in (3, 4)) ";
  141. }
  142. else{
  143. $s .= ") ";
  144. }
  145. }
  146. if (count($this->filters["TYPE"]) == 1){
  147. // Only one selectd, it's either gems or grindstones
  148. if (in_array("GEM", $this->filters["TYPE"])){
  149. $s .= " AND type IN (1, 3, 5) "; // Gems.
  150. }
  151. else{
  152. $s .= " AND type IN (2, 4, 6) "; // Grindstones.
  153. }
  154. }
  155. $s = $s . "
  156. ORDER BY
  157. type = 3 DESC, -- Inmemorial Grindstone
  158. type = 4 DESC, -- Inmemorial Gem
  159. rune,
  160. type,
  161. quality DESC,
  162. stat
  163. ";
  164. /*if (count($this->filters["MAIN"]) > 0){
  165. $s = $s . " AND main_stat IN ( ";
  166. foreach($this->filters["MAIN"] as $t){
  167. $s = $s . "$t, ";
  168. }
  169. $s = $s . "-1) ";
  170. }
  171. if (count($this->filters["ELEMENT"]) == 0 && count($this->filters["ARCHETYPE"]) == 0){
  172. // No element/archetype conditions
  173. }
  174. elseif (count($this->filters["ELEMENT"]) > 0 && count($this->filters["ARCHETYPE"]) == 0){
  175. // Only selected elements
  176. $s = $s . " AND attribute IN ( ";
  177. foreach($this->filters["ELEMENT"] as $t){
  178. $s = $s . "$t, ";
  179. }
  180. $s = $s . "-1) ";
  181. }
  182. elseif (count($this->filters["ELEMENT"]) == 0 && count($this->filters["ARCHETYPE"]) > 0){
  183. // Only selected types
  184. $s = $s . " AND archetype IN ( ";
  185. foreach($this->filters["ARCHETYPE"] as $t){
  186. $s = $s . "$t, ";
  187. }
  188. $s = $s . "-1) ";
  189. }
  190. elseif (count($this->filters["ELEMENT"]) > 0 && count($this->filters["ARCHETYPE"]) > 0){
  191. // Selected elements and selected types
  192. $s = $s . " AND (archetype IN ( ";
  193. foreach($this->filters["ARCHETYPE"] as $t){
  194. $s = $s . "$t, ";
  195. }
  196. $s = $s . "-1) OR attribute IN ( ";
  197. foreach($this->filters["ELEMENT"] as $t){
  198. $s = $s . "$t, ";
  199. }
  200. $s = $s . "-1)) ";
  201. }
  202. switch ($this->filters["ASSIGNED"]){
  203. case 1:
  204. $s = $s . " AND assigned_to IS NOT NULL ";
  205. break;
  206. case 2:
  207. $s = $s . " AND assigned_to IS NULL ";
  208. break;
  209. case 3:
  210. $s = $s . " AND (assigned_to IS NULL OR assigned_to IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ")) ";
  211. break;
  212. case 4:
  213. $s = $s . " AND assigned_to IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ") ";
  214. break;
  215. }
  216. $s = $s . " ORDER BY type, attribute, archetype, level DESC, original_quality DESC;";
  217. */
  218. return $s;
  219. }
  220. }
  221. ?>