Fusion_Page.php 2.7 KB

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