Report_Skillup_Page.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "Monster.php");
  4. /**
  5. * Urgent Skillup report page.
  6. */
  7. class Report_Skillup_Page extends Page{
  8. /**
  9. * Array of @{see Monsters}s.
  10. */
  11. public $monsters = [];
  12. public $filters = [
  13. "min_stars" => 1,
  14. "max_stars" => 6,
  15. "min_natural_stars" => 1,
  16. "max_natural_stars" => 5,
  17. "in_storage" => true,
  18. "without_runes" => true
  19. ];
  20. /**
  21. * Constructor.
  22. *
  23. * Retrieves the data and initializes the variables.
  24. *
  25. * @param SQLite3 $db Connection to the database.
  26. */
  27. public function __construct($db){
  28. global $path;
  29. global $root;
  30. parent::__construct($db);
  31. $this->view = $path["view"] . "report_skillup.php";
  32. $this->parse_filters();
  33. $s_mon = $this->build_query();
  34. error_log($s_mon);
  35. $q_mon = $this->db->query($s_mon);
  36. while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
  37. array_push($this->monsters, new Monster($db, $r_mon["id"]));
  38. }
  39. $this->title = "Urgent skill-ups - SWDB";
  40. $this->description = "Monster in need os skilling up";
  41. $this->canonical = $root . "report/skillups";
  42. }
  43. private function parse_filters(){
  44. if (isset($_GET["min_stars"]) && intval($_GET["min_stars"]) > 0 && intval($_GET["min_stars"]) < 7){
  45. $this->filters["min_stars"] = $_GET["min_stars"];
  46. }
  47. if (isset($_GET["max_stars"]) && intval($_GET["max_stars"]) > 0 && intval($_GET["max_stars"]) < 7){
  48. $this->filters["max_stars"] = $_GET["max_stars"];
  49. }
  50. if (isset($_GET["min_natural_stars"]) && intval($_GET["min_natural_stars"]) > 0 && intval($_GET["min_natural_stars"]) < 6){
  51. $this->filters["min_natural_stars"] = $_GET["min_natural_stars"];
  52. }
  53. if (isset($_GET["max_natural_stars"]) && intval($_GET["max_natural_stars"]) > 0 && intval($_GET["max_natural_stars"]) < 6){
  54. $this->filters["max_natural_stars"] = $_GET["max_natural_stars"];
  55. }
  56. if (isset($_GET["in_storage"]) && $_GET["in_storage"] != "on"){
  57. $this->filters["in_storage"] = false;
  58. }
  59. if (isset($_GET["without_runes"]) && $_GET["without_runes"] != "on"){
  60. $this->filters["without_runes"] = false;
  61. }
  62. return;
  63. }
  64. private function build_query(){
  65. $s =
  66. "SELECT DISTINCT " .
  67. " monster.id AS id, " .
  68. " sum( " .
  69. " CASE k_skill.slot " .
  70. " WHEN 1 THEN (monster.skill_1_level - 1) * 1 " .
  71. " WHEN 2 THEN (monster.skill_2_level - 1) * 1.5 " .
  72. " WHEN 3 THEN (monster.skill_3_level - 1) * 2 " .
  73. " WHEN 4 THEN (monster.skill_4_level - 1) * 2.5 " .
  74. " END " .
  75. " ) AS ponderated_level, " .
  76. " sum( " .
  77. " CASE k_skill.slot " .
  78. " WHEN 1 THEN (monster.skill_1_level - 1) " .
  79. " WHEN 2 THEN (monster.skill_2_level - 1) " .
  80. " WHEN 3 THEN (monster.skill_3_level - 1) " .
  81. " WHEN 4 THEN (monster.skill_4_level - 1) " .
  82. " END " .
  83. " ) AS level, " .
  84. " sum( " .
  85. " CASE k_skill.slot " .
  86. " WHEN 1 THEN (k_skill.max_level - 1) * 1 " .
  87. " WHEN 2 THEN (k_skill.max_level - 1) * 1.5 " .
  88. " WHEN 3 THEN (k_skill.max_level - 1) * 2 " .
  89. " WHEN 4 THEN (k_skill.max_level - 1) * 2.5 " .
  90. " END " .
  91. " ) AS ponderated_max_level, " .
  92. " sum( " .
  93. " CASE k_skill.slot " .
  94. " WHEN 1 THEN (k_skill.max_level - 1) " .
  95. " WHEN 2 THEN (k_skill.max_level - 1) " .
  96. " WHEN 3 THEN (k_skill.max_level - 1) " .
  97. " WHEN 4 THEN (k_skill.max_level - 1) " .
  98. " END " .
  99. " ) AS max_level " .
  100. "FROM " .
  101. " monster, " .
  102. " k_monster_skill, " .
  103. " k_skill, " .
  104. " k_monster " .
  105. "WHERE " .
  106. " monster.monster = k_monster_skill.monster AND " .
  107. " k_skill.id = k_monster_skill.skill AND " .
  108. " k_monster.id = monster.monster AND " .
  109. " k_skill.max_level > 1 AND " .
  110. " monster.stars >= " . $this->filters["min_stars"] . " AND " .
  111. " monster.stars <= " . $this->filters["max_stars"] . " AND " .
  112. " k_monster.natural_stars >= " . $this->filters["min_natural_stars"] . " AND " .
  113. " k_monster.natural_stars <= " . $this->filters["max_natural_stars"] . " ";
  114. if (!$this->filters["in_storage"]){
  115. $s = $s . " AND monster.in_storage = 0 ";
  116. }
  117. if (!$this->filters["without_runes"]){
  118. $s = $s . " AND monster.id IN (SELECT DISTINCT monster FROM monster_rune) ";
  119. }
  120. $s = $s .
  121. "GROUP BY monster.id " .
  122. "ORDER BY " .
  123. " ponderated_level * 100 / ponderated_max_level, " .
  124. " monster.stars DESC, " .
  125. " monster.level DESC, " .
  126. " level * 100 / max_level, " .
  127. " max_level - level DESC; ";
  128. return $s;
  129. }
  130. }
  131. ?>