Catalog_Page.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. /**
  4. * Catalog page model.
  5. */
  6. class Catalog_Page extends Page{
  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. */
  18. public function __construct($db){
  19. global $path;
  20. global $root;
  21. parent::__construct($db);
  22. $this->view = $path["view"] . "catalog.php";
  23. $s =
  24. "SELECT id, " .
  25. " element, " .
  26. " name, " .
  27. " img, " .
  28. " img_aw, " .
  29. " stars, " .
  30. " awakeable, " .
  31. " ( " .
  32. " SELECT count(id) > 0 " .
  33. " FROM monster_collection " .
  34. " WHERE monster = monster.id " .
  35. " ) AS owned " .
  36. "FROM monster " .
  37. "ORDER BY " .
  38. " element, " .
  39. " stars, " .
  40. " awakeable ";
  41. $q = $this->db->query($s);
  42. error_log($s);
  43. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  44. $mon = [
  45. "id" => $r["id"],
  46. "element" => $r["element"],
  47. "name" => $r["name"],
  48. "image" => $path["img"]["monster"] . $r["img"],
  49. "image_aw" => $path["img"]["monster"] . $r["img_aw"],
  50. "stars" => $r["stars"],
  51. "awakeable" => $r["awakeable"],
  52. "owned" => $r["owned"],
  53. ];
  54. array_push($this->entry, $mon);
  55. }
  56. $this->title = "Catalog - SWDB";
  57. $this->name = "SWDB";
  58. $this->description = "Catalog of all monsters";
  59. $this->favicon = "";
  60. $this->icon = "";
  61. $this->canonical = $root . "/catalog/";
  62. $this->author = $root;
  63. }
  64. }
  65. ?>