Report_Runecraft_Page.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <?php
  2. /**
  3. * Upgradeable runes report 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 . "Unit.php");
  14. require_once(PATH::ENTITY . "Rune.php");
  15. require_once(PATH::ENTITY . "Rune_Craft.php");
  16. /**
  17. * Upgradeable runes report page model.
  18. *
  19. * @category Page
  20. */
  21. class Report_Runecraft_Page extends Page{
  22. /**
  23. * @var mixed[] List of available upgrades.
  24. *
  25. * Can be described as:
  26. * $upgrades = [
  27. * [
  28. * unit (Unit),
  29. * upgrade = [
  30. * [
  31. * rune (Rune),
  32. * craft = [(Rune_Craft)]
  33. * ]
  34. * ]
  35. * ]
  36. * ]
  37. */
  38. public $upgrades = [];
  39. /**
  40. * Constructor.
  41. *
  42. * Retrieves the data and initializes the variables.
  43. *
  44. * @global resource Database connection.
  45. */
  46. public function __construct(){
  47. global $db;
  48. $this->view = PATH::VIEW . "report_runecraft.php";
  49. $this->parse_filters();
  50. $s = $this->build_query();
  51. $q = $db->query($s);
  52. $prev_monster = "";
  53. $prev_rune = "";
  54. $upgrade = null;
  55. $rupgrade = null;
  56. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  57. if ($r["unit"] != $prev_monster){
  58. if ($prev_rune != ""){
  59. array_push($upgrade["upgrade"], $rupgrade);
  60. }
  61. if ($prev_monster != ""){
  62. array_push($this->upgrades, $upgrade);
  63. }
  64. $prev_monster = $r["unit"];
  65. $prev_rune = "";
  66. $upgrade = [
  67. "unit" => new Unit($r["unit"]),
  68. "upgrade" => [],
  69. ];
  70. $rupgrade = [
  71. "rune" => new Rune($r["rune"]),
  72. "craft" => [],
  73. ];
  74. }
  75. if ($r["rune"] != $prev_rune){
  76. if ($prev_rune != ""){
  77. array_push($upgrade["upgrade"], $rupgrade);
  78. }
  79. $prev_rune = $r["rune"];
  80. $rupgrade = [
  81. "rune" => new Rune($r["rune"]),
  82. "craft" => [],
  83. ];
  84. }
  85. $rune_craft = new Rune_craft($r["craft"]);
  86. array_push($rupgrade["craft"], $rune_craft);
  87. }
  88. // Last entries
  89. array_push($upgrade["upgrade"], $rupgrade);
  90. array_push($this->upgrades, $upgrade);
  91. $this->title = "Rune craft - SWDB";
  92. $this->description = "Find runes that can be upgraded via crafting.";
  93. $this->canonical = URL::BASE . "report/runecraft/";
  94. }
  95. /**
  96. * Parses the filters passed in the request and sets $filters.
  97. * Filters must be in $_GET, nd the available ones are max_stars (1-6),
  98. * min_stars (1-6) and in_storage (on/off).
  99. */
  100. private function parse_filters(){
  101. $this->filters = FILTER::RUNECRAFT;
  102. // Monster
  103. if (isset($_GET["monster_min_stars"]) && intval($_GET["monster_min_stars"]) > 0 && intval($_GET["monster_min_stars"]) < 7){
  104. $this->filters["MONSTER_MIN_STARS"] = $_GET["monster_min_stars"];
  105. }
  106. if (isset($_GET["monster_max_stars"]) && intval($_GET["monster_max_stars"]) > 0 && intval($_GET["monster_max_stars"]) < 7){
  107. $this->filters["MONSTER_MAX_STARS"] = $_GET["monster_max_stars"];
  108. }
  109. if (isset($_GET["monster_in_storage"]) && $_GET["monster_in_storage"] == "on"){
  110. $this->filters["MONSTER_IN_STORAGE"] = true;
  111. }
  112. else{
  113. $this->filters["MONSTER_IN_STORAGE"] = false;
  114. }
  115. if (isset($_GET["monster_name"]) && strlen($_GET["monster_name"]) > 0){
  116. $this->filters["MONSTER_NAME"] = SQLite3::escapeString($_GET["monster_name"]);
  117. }
  118. // Runes
  119. if (isset($_GET["rune_min_stars"]) && intval($_GET["rune_min_stars"]) > 0 && intval($_GET["rune_min_stars"]) < 7){
  120. $this->filters["RUNE_MIN_STARS"] = $_GET["rune_min_stars"];
  121. }
  122. if (isset($_GET["rune_max_stars"]) && intval($_GET["rune_max_stars"]) > 0 && intval($_GET["rune_max_stars"]) < 7){
  123. $this->filters["RUNE_MAX_STARS"] = $_GET["rune_max_stars"];
  124. }
  125. if (isset($_GET["rune_min_level"]) && intval($_GET["rune_min_level"]) >= 0 && intval($_GET["rune_min_level"]) <= 15){
  126. $this->filters["RUNE_MIN_LEVEL"] = $_GET["rune_min_level"];
  127. }
  128. if (isset($_GET["rune_max_level"]) && intval($_GET["rune_max_level"]) >= 0 && intval($_GET["rune_max_level"]) <= 15){
  129. $this->filters["RUNE_MAX_LEVEL"] = $_GET["rune_max_level"];
  130. }
  131. if (isset($_GET["rune_min_quality"]) && intval($_GET["rune_min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_min_quality"]) <= QUALITY_ID::LEGEND){
  132. $this->filters["RUNE_MIN_QUALITY"] = $_GET["rune_min_quality"];
  133. }
  134. if (isset($_GET["rune_max_quality"]) && intval($_GET["rune_max_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_max_quality"]) <= QUALITY_ID::LEGEND){
  135. $this->filters["RUNE_MAX_QUALITY"] = $_GET["rune_max_quality"];
  136. }
  137. if (isset($_GET["rune_min_original_quality"]) && intval($_GET["rune_min_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_min_original_quality"]) <= QUALITY_ID::LEGEND){
  138. $this->filters["RUNE_MIN_ORIGINAL_QUALITY"] = $_GET["rune_min_original_quality"];
  139. }
  140. if (isset($_GET["rune_max_original_quality"]) && intval($_GET["rune_max_original_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_max_original_quality"]) <= QUALITY_ID::LEGEND){
  141. $this->filters["RUNE_MAX_ORIGINAL_QUALITY"] = $_GET["rune_max_original_quality"];
  142. }
  143. if (isset($_GET["rune_min_efficiency"]) && intval($_GET["rune_min_efficiency"]) >= 0 && intval($_GET["rune_min_efficiency"]) <= 100){
  144. $this->filters["RUNE_MIN_EFFICIENCY"] = $_GET["rune_min_efficiency"];
  145. }
  146. if (isset($_GET["rune_max_efficiency"]) && intval($_GET["rune_max_efficiency"]) >= 0 && intval($_GET["rune_max_efficiency"]) <= 100){
  147. $this->filters["RUNE_MAX_EFFICIENCY"] = $_GET["rune_max_efficiency"];
  148. }
  149. if (isset($_GET["rune_min_max_efficiency"]) && intval($_GET["rune_min_max_efficiency"]) >= 0 && intval($_GET["rune_min_max_efficiency"]) <= 100){
  150. $this->filters["RUNE_MIN_MAX_EFFICIENCY"] = $_GET["rune_min_max_efficiency"];
  151. }
  152. if (isset($_GET["rune_max_max_efficiency"]) && intval($_GET["rune_max_max_efficiency"]) >= 0 && intval($_GET["rune_max_max_efficiency"]) <= 100){
  153. $this->filters["RUNE_MAX_MAX_EFFICIENCY"] = $_GET["rune_max_max_efficiency"];
  154. }
  155. if (isset($_GET["rune_slot"])){
  156. $slots = $_GET["rune_slot"];
  157. foreach ($slots as $slot){
  158. if (intval($slot) >= 1 && intval($slot) < 7){
  159. array_push($this->filters["RUNE_SLOT"], intval($slot));
  160. }
  161. }
  162. }
  163. // Grindstones
  164. if (isset($_GET["grind_min_quality"]) && intval($_GET["grind_min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["grind_min_quality"]) < QUALITY_ID::LEGEND){
  165. $this->filters["GRIND_MIN_QUALITY"] = $_GET["grind_min_quality"];
  166. }
  167. if (isset($_GET["grind_stat"])){
  168. $stats = $_GET["grind_stat"];
  169. $this->filters["GRIND_STAT"] = [];
  170. foreach ($stats as $stat){
  171. array_push($this->filters["GRIND_STAT"], intval($stat));
  172. }
  173. }
  174. if (isset($_GET["gem_stat_from"])){
  175. $stats = $_GET["gem_stat_from"];
  176. $this->filters["GEM_STAT_FROM"] = [];
  177. foreach ($stats as $stat){
  178. array_push($this->filters["GEM_STAT_FROM"], intval($stat));
  179. }
  180. }
  181. if (isset($_GET["gem_stat_to"])){
  182. $stats = $_GET["gem_stat_to"];
  183. $this->filters["GEM_STAT_TO"] = [];
  184. foreach ($stats as $stat){
  185. array_push($this->filters["GEM_STAT_TO"], intval($stat));
  186. }
  187. }
  188. return;
  189. }
  190. /**
  191. * Builds the query for the page, using the providded or default filters.
  192. *
  193. * @return string The query to be executed.
  194. * @global int Player ID.
  195. */
  196. private function build_query(){
  197. global $UID;
  198. $s = "
  199. SELECT
  200. unit.id AS unit,
  201. rune.id AS rune,
  202. rune_craft.id AS craft
  203. FROM
  204. unit,
  205. k_unit,
  206. rune,
  207. rune_craft,
  208. k_rune_craft_type
  209. WHERE
  210. unit.uid = '$UID' AND
  211. rune.uid = '$UID' AND
  212. rune_craft.uid = '$UID' AND
  213. unit.id = rune.assigned_to AND
  214. unit.unit = k_unit.id AND
  215. rune_craft.type = k_rune_craft_type.id AND
  216. unit.stars >= " . $this->filters["RUNE_MIN_STARS"] . " AND
  217. unit.stars <= " . $this->filters["RUNE_MAX_STARS"] . " AND
  218. -- RUNE FILTERS
  219. rune.quality >= " . $this->filters["RUNE_MIN_QUALITY"] . " AND
  220. rune.quality <= " . $this->filters["RUNE_MAX_QUALITY"] . " AND
  221. rune.level >= " . $this->filters["RUNE_MIN_LEVEL"] . " AND
  222. rune.level <= " . $this->filters["RUNE_MAX_LEVEL"] . " AND
  223. rune.stars >= " . $this->filters["RUNE_MIN_STARS"] . " AND
  224. rune.stars <= " . $this->filters["RUNE_MAX_STARS"] . " AND
  225. rune.original_quality >= " . $this->filters["RUNE_MIN_ORIGINAL_QUALITY"] . " AND
  226. rune.original_quality <= " . $this->filters["RUNE_MAX_ORIGINAL_QUALITY"] . " AND
  227. rune.efficiency >= " . $this->filters["RUNE_MIN_EFFICIENCY"] . " AND
  228. rune.efficiency <= " . $this->filters["RUNE_MAX_EFFICIENCY"] . " AND
  229. rune.max_efficiency >= " . $this->filters["RUNE_MIN_MAX_EFFICIENCY"] . " AND
  230. rune.max_efficiency <= " . $this->filters["RUNE_MAX_MAX_EFFICIENCY"] . " AND
  231. (
  232. rune.type = rune_craft.rune OR
  233. k_rune_craft_type.inmemorial = 1
  234. ) AND
  235. k_rune_craft_type.ancient = rune.ancient AND
  236. ";
  237. if (strlen($this->filters["MONSTER_NAME"]) > 0){
  238. $s = $s . " upper(k_unit.name) LIKE = upper('%" . $this->filters["MONSTER_NAME"] . "%') AND ";
  239. }
  240. if (!$this->filters["MONSTER_IN_STORAGE"]){
  241. $s = $s . " unit.building <> " . BUILDING_ID::MONSTER_STORAGE . " AND ";
  242. }
  243. if (count($this->filters["RUNE_SLOT"]) > 0){
  244. $s = $s . " rune.slot IN ( ";
  245. foreach($this->filters["RUNE_SLOT"] as $t){
  246. $s = $s . "$t, ";
  247. }
  248. $s = $s . "-1) AND ";
  249. }
  250. $s .= "
  251. rune_craft.stat <> rune.main_stat AND
  252. rune_craft.stat <> rune.innate_stat AND
  253. (
  254. k_rune_craft_type.gem = 1 AND
  255. (
  256. -- GEM FILTERS
  257. rune_craft.quality >= " . $this->filters["GEM_MIN_QUALITY"] . " AND
  258. ";
  259. if (count($this->filters["GEM_STAT_FROM"]) > 0){
  260. $in = "(";
  261. foreach($this->filters["GEM_STAT_FROM"] as $t){
  262. $in = $in . "$t, ";
  263. }
  264. $in = $in . "-1)";
  265. $s .= " (rune.substat_1 IN $in OR rune.substat_2 IN $in OR rune.substat_3 IN $in OR rune.substat_4 IN $in) AND ";
  266. }
  267. if (count($this->filters["GEM_STAT_TO"]) > 0){
  268. $in = "(";
  269. foreach($this->filters["GEM_STAT_TO"] as $t){
  270. $in = $in . "$t, ";
  271. }
  272. $in = $in . "-1)";
  273. $s .= " rune_craft.stat IN $in AND ";
  274. }
  275. $s .= "
  276. (
  277. rune_craft.stat <> rune.substat_1 AND
  278. rune_craft.stat <> rune.substat_2 AND
  279. rune_craft.stat <> rune.substat_3 AND
  280. rune_craft.stat <> rune.substat_4
  281. )
  282. )
  283. ) |
  284. (
  285. k_rune_craft_type.gem = 0 AND
  286. (
  287. -- GRINDSTONE FILTERS
  288. ";
  289. if (count($this->filters["GRIND_STAT"]) > 0){
  290. $in = "(";
  291. foreach($this->filters["GRIND_STAT"] as $t){
  292. $in = $in . "$t, ";
  293. }
  294. $in = $in . "-1)";
  295. $s .= " rune_craft.stat IN $in AND ";
  296. }
  297. $s .= "
  298. rune_craft.quality >= " . $this->filters["GRIND_MIN_QUALITY"] . " AND
  299. (
  300. (
  301. rune_craft.stat = rune.substat_1 AND
  302. rune_craft.stat <> rune.substat_2 AND
  303. rune_craft.stat <> rune.substat_3 AND
  304. rune_craft.stat <> rune.substat_4
  305. ) OR
  306. (
  307. rune_craft.stat <> rune.substat_1 AND
  308. rune_craft.stat = rune.substat_2 AND
  309. rune_craft.stat <> rune.substat_3 AND
  310. rune_craft.stat <> rune.substat_4
  311. ) OR
  312. (
  313. rune_craft.stat <> rune.substat_1 AND
  314. rune_craft.stat <> rune.substat_2 AND
  315. rune_craft.stat = rune.substat_3 AND
  316. rune_craft.stat <> rune.substat_4
  317. ) OR
  318. (
  319. rune_craft.stat <> rune.substat_1 AND
  320. rune_craft.stat <> rune.substat_2 AND
  321. rune_craft.stat <> rune.substat_3 AND
  322. rune_craft.stat = rune.substat_4
  323. )
  324. )
  325. )
  326. )
  327. ";
  328. $s .= "
  329. ORDER BY
  330. unit.stars DESC,
  331. unit.level DESC,
  332. unit.id,
  333. rune.stars DESC,
  334. rune.original_quality DESC,
  335. rune.level DESC,
  336. rune.id,
  337. rune.slot,
  338. rune_craft.quality DESC,
  339. rune_craft.stat DESC;
  340. ";
  341. return $s;
  342. }
  343. }
  344. ?>