Fusion_Page.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "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 $UID;
  32. global $path;
  33. global $root;
  34. parent::__construct($db);
  35. $this->view = $path["view"] . "fusion.php";
  36. $this->parse_filters();
  37. $s =
  38. "SELECT DISTINCT product " .
  39. "FROM k_fusion " .
  40. "WHERE stars = 5 " .
  41. "ORDER BY stars DESC; ";
  42. $q = $this->db->query($s);
  43. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  44. array_push($this->products, new K_Unit($this->db, $r["product"], false));
  45. }
  46. $s = $this->build_query();
  47. $q = $this->db->query($s);
  48. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  49. array_push($this->fusion, new Fusion($this->db, $r["product"], $UID));
  50. }
  51. $this->title = "Fusion - SWDB";
  52. $this->description = "Fusion chart";
  53. $this->canonical = $root . "fusion/";
  54. }
  55. /**
  56. * Parses the request looking for the selected filters, validates them
  57. * and adds them to the $filters array.
  58. */
  59. private function parse_filters(){
  60. if (isset($_GET["product"]) && intval($_GET["product"]) > 0){
  61. $this->filters["product"] = $_GET["product"];
  62. }
  63. return;
  64. }
  65. /**
  66. * Builds the query to the rune table using the selected or default
  67. * filters.
  68. *
  69. * @return The query to be executed.
  70. */
  71. private function build_query(){
  72. $s =
  73. "SELECT DISTINCT product " .
  74. "FROM k_fusion " .
  75. "WHERE stars = 5 ";
  76. if ($this->filters["product"] > 0){
  77. $s = $s . " AND product = " . strtoupper($this->filters["product"]) . " ";
  78. }
  79. $s = $s . "ORDER BY stars DESC;";
  80. return $s;
  81. }
  82. }
  83. ?>