Catalog_List_Frame.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. require_once($path["frame"] . "Frame.php");
  3. /**
  4. * Catalog's page monster list.
  5. */
  6. class Catalog_List_Frame extends Frame{
  7. /**
  8. * List of all the monsters in the database.
  9. */
  10. public $entry = [];
  11. /**
  12. * Constructor.
  13. *
  14. * Retrieves the data and initializes the variables.
  15. *
  16. * @param SQLite3 $db Connection to the database.
  17. * @param Array $params Parameters array. May contain the 'selected' parameter
  18. * to mark a monster as selected.
  19. */
  20. public function __construct($db, $params){
  21. global $path;
  22. parent::__construct($db);
  23. $this->view = $path["view"] . "frame/catalog_list.php";
  24. $w_name = "1 = 1";
  25. $w_type = "1 = 1";
  26. $w_element = "1 = 1";
  27. $w_min_stars = "1 = 1";
  28. $w_max_stars = "1 = 1";
  29. if (isset($params["name"])){
  30. $w_name = "(name LIKE '%" . $params["name"] . "%' OR name_aw LIKE '%" . $params["name"] . "%')";
  31. }
  32. if (isset($params["type"])){
  33. $w_type = "type = '" . $params["type"] . "'";
  34. }
  35. if (isset($params["element"])){
  36. $w_element = "element = '" . $params["element"] . "'";
  37. }
  38. if (isset($params["minstars"]) && intval($params["minstars"]) > 0 && intval($params["minstars"]) < 7){
  39. $w_min_stars = "stars >= " . $params["minstars"];
  40. }
  41. if (isset($params["maxstars"]) && intval($params["maxstars"]) > 0 && intval($params["maxstars"]) < 7){
  42. $w_max_stars = "stars <= " . $params["maxstars"];
  43. }
  44. $s =
  45. "SELECT id, " .
  46. " element, " .
  47. " name, " .
  48. " img, " .
  49. " img_aw, " .
  50. " stars, " .
  51. " awakeable, " .
  52. " ( " .
  53. " SELECT count(id) > 0 " .
  54. " FROM monster_collection " .
  55. " WHERE monster = monster.id " .
  56. " ) AS owned " .
  57. "FROM monster " .
  58. "WHERE " .
  59. " $w_name AND " .
  60. " $w_type AND " .
  61. " $w_element AND " .
  62. " $w_min_stars AND " .
  63. " $w_max_stars " .
  64. "ORDER BY " .
  65. " element, " .
  66. " stars, " .
  67. " awakeable ";
  68. $q = $this->db->query($s);
  69. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  70. $mon = [
  71. "id" => $r["id"],
  72. "element" => $r["element"],
  73. "name" => $r["name"],
  74. "image" => $path["img"]["monster"] . $r["img"],
  75. "image_aw" => $path["img"]["monster"] . $r["img_aw"],
  76. "stars" => $r["stars"],
  77. "awakeable" => $r["awakeable"],
  78. "owned" => $r["owned"],
  79. ];
  80. array_push($this->entry, $mon);
  81. }
  82. }
  83. }
  84. ?>