Report_Rune_Enchantment_Page.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 . "Enchantment.php");
  16. /**
  17. * Upgradeable runes report page model.
  18. *
  19. * @category Page
  20. */
  21. class Report_Rune_Enchantment_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. * enchant = [(Enchantment)]
  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_rune_enchantment.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. "enchantment" => [],
  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. "enchantment" => [],
  133. ];
  134. }
  135. $enchantment= new Enchantment($r["enchantment"]);
  136. array_push($rupgrade["enchantment"], $enchantment);
  137. }
  138. // Last entries
  139. array_push($upgrade["upgrade"], $rupgrade);
  140. array_push($this->upgrades, $upgrade);
  141. $this->title = "Rune enchantment - SWDB";
  142. $this->description = "Find runes that can be upgraded via enchantments.";
  143. $this->canonical = URL::BASE . "report/rune_enchantment/";
  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. // Monster
  152. if (isset($_GET["monster_min_stars"]) && intval($_GET["monster_min_stars"]) > 0 && intval($_GET["monster_min_stars"]) < 7){
  153. $this->filters["MONSTER_MIN_STARS"] = $_GET["monster_min_stars"];
  154. }
  155. if (isset($_GET["monster_max_stars"]) && intval($_GET["monster_max_stars"]) > 0 && intval($_GET["monster_max_stars"]) < 7){
  156. $this->filters["MONSTER_MAX_STARS"] = $_GET["monster_max_stars"];
  157. }
  158. if (isset($_GET["monster_in_storage"]) && $_GET["monster_in_storage"] == "on"){
  159. $this->filters["MONSTER_IN_STORAGE"] = true;
  160. }
  161. else{
  162. $this->filters["MONSTER_IN_STORAGE"] = false;
  163. }
  164. if (isset($_GET["monster_name"]) && strlen($_GET["monster_name"]) > 0){
  165. $this->filters["MONSTER_NAME"] = SQLite3::escapeString($_GET["monster_name"]);
  166. }
  167. // Runes
  168. if (isset($_GET["rune_min_stars"]) && intval($_GET["rune_min_stars"]) > 0 && intval($_GET["rune_min_stars"]) < 7){
  169. $this->filters["RUNE_MIN_STARS"] = $_GET["rune_min_stars"];
  170. }
  171. if (isset($_GET["rune_max_stars"]) && intval($_GET["rune_max_stars"]) > 0 && intval($_GET["rune_max_stars"]) < 7){
  172. $this->filters["RUNE_MAX_STARS"] = $_GET["rune_max_stars"];
  173. }
  174. if (isset($_GET["rune_min_level"]) && intval($_GET["rune_min_level"]) >= 0 && intval($_GET["rune_min_level"]) <= 15){
  175. $this->filters["RUNE_MIN_LEVEL"] = $_GET["rune_min_level"];
  176. }
  177. if (isset($_GET["rune_max_level"]) && intval($_GET["rune_max_level"]) >= 0 && intval($_GET["rune_max_level"]) <= 15){
  178. $this->filters["RUNE_MAX_LEVEL"] = $_GET["rune_max_level"];
  179. }
  180. if (isset($_GET["rune_min_quality"]) && intval($_GET["rune_min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_min_quality"]) <= QUALITY_ID::LEGEND){
  181. $this->filters["RUNE_MIN_QUALITY"] = $_GET["rune_min_quality"];
  182. }
  183. if (isset($_GET["rune_max_quality"]) && intval($_GET["rune_max_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["rune_max_quality"]) <= QUALITY_ID::LEGEND){
  184. $this->filters["RUNE_MAX_QUALITY"] = $_GET["rune_max_quality"];
  185. }
  186. 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){
  187. $this->filters["RUNE_MIN_ORIGINAL_QUALITY"] = $_GET["rune_min_original_quality"];
  188. }
  189. 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){
  190. $this->filters["RUNE_MAX_ORIGINAL_QUALITY"] = $_GET["rune_max_original_quality"];
  191. }
  192. if (isset($_GET["rune_min_efficiency"]) && intval($_GET["rune_min_efficiency"]) >= 0 && intval($_GET["rune_min_efficiency"]) <= 100){
  193. $this->filters["RUNE_MIN_EFFICIENCY"] = $_GET["rune_min_efficiency"];
  194. }
  195. if (isset($_GET["rune_max_efficiency"]) && intval($_GET["rune_max_efficiency"]) >= 0 && intval($_GET["rune_max_efficiency"]) <= 100){
  196. $this->filters["RUNE_MAX_EFFICIENCY"] = $_GET["rune_max_efficiency"];
  197. }
  198. if (isset($_GET["rune_min_max_efficiency"]) && intval($_GET["rune_min_max_efficiency"]) >= 0 && intval($_GET["rune_min_max_efficiency"]) <= 100){
  199. $this->filters["RUNE_MIN_MAX_EFFICIENCY"] = $_GET["rune_min_max_efficiency"];
  200. }
  201. if (isset($_GET["rune_max_max_efficiency"]) && intval($_GET["rune_max_max_efficiency"]) >= 0 && intval($_GET["rune_max_max_efficiency"]) <= 100){
  202. $this->filters["RUNE_MAX_MAX_EFFICIENCY"] = $_GET["rune_max_max_efficiency"];
  203. }
  204. if (isset($_GET["rune_slot"])){
  205. $slots = $_GET["rune_slot"];
  206. foreach ($slots as $slot){
  207. if (intval($slot) >= 1 && intval($slot) < 7){
  208. array_push($this->filters["RUNE_SLOT"], intval($slot));
  209. }
  210. }
  211. }
  212. // Grindstones
  213. if (isset($_GET["grind_min_quality"]) && intval($_GET["grind_min_quality"]) >= QUALITY_ID::NORMAL && intval($_GET["grind_min_quality"]) < QUALITY_ID::LEGEND){
  214. $this->filters["GRIND_MIN_QUALITY"] = $_GET["grind_min_quality"];
  215. }
  216. if (isset($_GET["grind_stat"])){
  217. $stats = $_GET["grind_stat"];
  218. $this->filters["GRIND_STAT"] = [];
  219. foreach ($stats as $stat){
  220. array_push($this->filters["GRIND_STAT"], intval($stat));
  221. }
  222. }
  223. if (isset($_GET["gem_stat_from"])){
  224. $stats = $_GET["gem_stat_from"];
  225. $this->filters["GEM_STAT_FROM"] = [];
  226. foreach ($stats as $stat){
  227. array_push($this->filters["GEM_STAT_FROM"], intval($stat));
  228. }
  229. }
  230. if (isset($_GET["gem_stat_to"])){
  231. $stats = $_GET["gem_stat_to"];
  232. $this->filters["GEM_STAT_TO"] = [];
  233. foreach ($stats as $stat){
  234. array_push($this->filters["GEM_STAT_TO"], intval($stat));
  235. }
  236. }
  237. return;
  238. }
  239. /**
  240. * Builds the query for the page, using the providded or default filters.
  241. *
  242. * @return string The query to be executed.
  243. * @global int Player ID.
  244. */
  245. private function build_query(){
  246. global $UID;
  247. $s = "
  248. SELECT
  249. unit.id AS unit,
  250. rune.id AS rune,
  251. enchantment.id AS enchantment
  252. FROM
  253. unit,
  254. k_unit,
  255. rune,
  256. enchantment,
  257. k_enchantment_type
  258. WHERE
  259. unit.uid = '$UID' AND
  260. rune.uid = '$UID' AND
  261. enchantment.uid = '$UID' AND
  262. unit.id = rune.assigned_to AND
  263. unit.unit = k_unit.id AND
  264. enchantment.type = k_enchantment_type.id AND
  265. unit.stars >= " . $this->filters["RUNE_MIN_STARS"] . " AND
  266. unit.stars <= " . $this->filters["RUNE_MAX_STARS"] . " AND
  267. -- RUNE FILTERS
  268. rune.quality >= " . $this->filters["RUNE_MIN_QUALITY"] . " AND
  269. rune.quality <= " . $this->filters["RUNE_MAX_QUALITY"] . " AND
  270. rune.level >= " . $this->filters["RUNE_MIN_LEVEL"] . " AND
  271. rune.level <= " . $this->filters["RUNE_MAX_LEVEL"] . " AND
  272. rune.stars >= " . $this->filters["RUNE_MIN_STARS"] . " AND
  273. rune.stars <= " . $this->filters["RUNE_MAX_STARS"] . " AND
  274. rune.original_quality >= " . $this->filters["RUNE_MIN_ORIGINAL_QUALITY"] . " AND
  275. rune.original_quality <= " . $this->filters["RUNE_MAX_ORIGINAL_QUALITY"] . " AND
  276. rune.efficiency >= " . $this->filters["RUNE_MIN_EFFICIENCY"] . " AND
  277. rune.efficiency <= " . $this->filters["RUNE_MAX_EFFICIENCY"] . " AND
  278. rune.max_efficiency >= " . $this->filters["RUNE_MIN_MAX_EFFICIENCY"] . " AND
  279. rune.max_efficiency <= " . $this->filters["RUNE_MAX_MAX_EFFICIENCY"] . " AND
  280. (
  281. rune.type = enchantment.rune OR
  282. k_enchantment_type.inmemorial = 1
  283. ) AND
  284. k_enchantment_type.ancient = rune.ancient AND
  285. ";
  286. if (strlen($this->filters["MONSTER_NAME"]) > 0){
  287. $s = $s . " upper(k_unit.name) LIKE upper('%" . $this->filters["MONSTER_NAME"] . "%') AND ";
  288. }
  289. if (!$this->filters["MONSTER_IN_STORAGE"]){
  290. $s = $s . " unit.building <> " . BUILDING_ID::MONSTER_STORAGE . " AND ";
  291. }
  292. if (count($this->filters["RUNE_SLOT"]) > 0){
  293. $s = $s . " rune.slot IN ( ";
  294. foreach($this->filters["RUNE_SLOT"] as $t){
  295. $s = $s . "$t, ";
  296. }
  297. $s = $s . "-1) AND ";
  298. }
  299. $s .= "
  300. enchantment.stat <> rune.main_stat AND
  301. enchantment.stat <> rune.innate_stat AND
  302. (
  303. k_enchantment_type.gem = 1 AND
  304. (
  305. -- GEM FILTERS
  306. enchantment.quality >= " . $this->filters["GEM_MIN_QUALITY"] . " AND
  307. ";
  308. if (count($this->filters["GEM_STAT_FROM"]) > 0){
  309. $in = "(";
  310. foreach($this->filters["GEM_STAT_FROM"] as $t){
  311. $in = $in . "$t, ";
  312. }
  313. $in = $in . "-1)";
  314. $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 ";
  315. }
  316. if (count($this->filters["GEM_STAT_TO"]) > 0){
  317. $in = "(";
  318. foreach($this->filters["GEM_STAT_TO"] as $t){
  319. $in = $in . "$t, ";
  320. }
  321. $in = $in . "-1)";
  322. $s .= " enchantment.stat IN $in AND ";
  323. }
  324. $s .= "
  325. (
  326. enchantment.stat <> rune.substat_1 AND
  327. enchantment.stat <> rune.substat_2 AND
  328. enchantment.stat <> rune.substat_3 AND
  329. enchantment.stat <> rune.substat_4
  330. )
  331. )
  332. ) |
  333. (
  334. k_enchantment_type.gem = 0 AND
  335. (
  336. -- GRINDSTONE FILTERS
  337. ";
  338. if (count($this->filters["GRIND_STAT"]) > 0){
  339. $in = "(";
  340. foreach($this->filters["GRIND_STAT"] as $t){
  341. $in = $in . "$t, ";
  342. }
  343. $in = $in . "-1)";
  344. $s .= " enchantment.stat IN $in AND ";
  345. }
  346. $s .= "
  347. enchantment.quality >= " . $this->filters["GRIND_MIN_QUALITY"] . " AND
  348. (
  349. (
  350. enchantment.stat = rune.substat_1 AND
  351. enchantment.stat <> rune.substat_2 AND
  352. enchantment.stat <> rune.substat_3 AND
  353. enchantment.stat <> rune.substat_4
  354. ) OR
  355. (
  356. enchantment.stat <> rune.substat_1 AND
  357. enchantment.stat = rune.substat_2 AND
  358. enchantment.stat <> rune.substat_3 AND
  359. enchantment.stat <> rune.substat_4
  360. ) OR
  361. (
  362. enchantment.stat <> rune.substat_1 AND
  363. enchantment.stat <> rune.substat_2 AND
  364. enchantment.stat = rune.substat_3 AND
  365. enchantment.stat <> rune.substat_4
  366. ) OR
  367. (
  368. enchantment.stat <> rune.substat_1 AND
  369. enchantment.stat <> rune.substat_2 AND
  370. enchantment.stat <> rune.substat_3 AND
  371. enchantment.stat = rune.substat_4
  372. )
  373. )
  374. )
  375. )
  376. ";
  377. $s .= "
  378. ORDER BY
  379. unit.stars DESC,
  380. unit.level DESC,
  381. unit.id,
  382. rune.stars DESC,
  383. rune.original_quality DESC,
  384. rune.level DESC,
  385. rune.id,
  386. rune.slot,
  387. enchantment.quality DESC,
  388. enchantment.stat DESC;
  389. ";
  390. return $s;
  391. }
  392. }
  393. ?>