Report_Runecraft_Page.php 17 KB

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