Fusion_Page.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Fusion 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 . "Fusion.php");
  14. require_once(PATH::ENTITY . "K_Unit.php");
  15. /**
  16. * Fusion page model.
  17. */
  18. class Fusion_Page extends Page{
  19. /**
  20. * @var \K_Fusion[] List of top-level fusions to display.
  21. */
  22. public $fusion = [];
  23. /**
  24. * @var \K_Unit[] List of top-level fuseable units (for filter).
  25. */
  26. public $products = [];
  27. /**
  28. * Constructor.
  29. *
  30. * Retrieves the data and initializes the variables.
  31. *
  32. * @global int User ID.
  33. * @global resource Connection to the database.
  34. */
  35. public function __construct(){
  36. global $UID;
  37. global $db;
  38. $this->view = PATH::VIEW . "fusion.php";
  39. $this->parse_filters();
  40. $s =
  41. "SELECT DISTINCT product " .
  42. "FROM k_fusion " .
  43. "WHERE stars = 5 " .
  44. "ORDER BY stars DESC; ";
  45. $q = $db->query($s);
  46. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  47. array_push($this->products, new K_Unit($r["product"], false));
  48. }
  49. $s = $this->build_query();
  50. $q = $db->query($s);
  51. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  52. array_push($this->fusion, new Fusion($r["product"], $UID));
  53. }
  54. $this->title = "Fusion - SWDB";
  55. $this->description = "Fusion chart";
  56. $this->canonical = URL::BASE . "fusion/";
  57. }
  58. /**
  59. * Parses the request looking for the selected filters, validates them
  60. * and adds them to the $filters array.
  61. */
  62. private function parse_filters(){
  63. $this->filters = FILTER::FUSION;
  64. if (isset($_GET["product"]) && intval($_GET["product"]) > 0){
  65. $this->filters["product"] = $_GET["product"];
  66. }
  67. return;
  68. }
  69. /**
  70. * Builds the query to the rune table using the selected or default
  71. * filters.
  72. *
  73. * @return string The query to be executed.
  74. */
  75. private function build_query(){
  76. $s =
  77. "SELECT DISTINCT product " .
  78. "FROM k_fusion " .
  79. "WHERE stars = 5 ";
  80. if ($this->filters["product"] > 0){
  81. $s = $s . " AND product = " . $this->filters["product"] . " ";
  82. }
  83. $s = $s . "ORDER BY stars DESC;";
  84. return $s;
  85. }
  86. }
  87. ?>