Monster_Collection.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Monster.php");
  4. /**
  5. * Owned monster.
  6. *
  7. * Represents an object from the table 'collection'.
  8. */
  9. class Monster_Collection extends Entity{
  10. /**
  11. * Collection item identifier.
  12. */
  13. public $id;
  14. /**
  15. * {@see Monster}.
  16. */
  17. public $monster;
  18. /**
  19. * Stars of the monster.
  20. */
  21. public $stars;
  22. /**
  23. * Monster level.
  24. */
  25. public $_level;
  26. /**
  27. * Monster awakened.
  28. */
  29. public $awaken;
  30. /**
  31. * Constructor.
  32. *
  33. * Searches the database and retrieves the information about the
  34. * owned monster, populating it and it's items.
  35. *
  36. * @param SQLite3 $db Connection to the database.
  37. * @param int $id Monster id in the collection.
  38. */
  39. public function __construct($db, $id){
  40. global $path;
  41. parent::__construct($db);
  42. $s =
  43. "SELECT " .
  44. " id, " .
  45. " monster, " .
  46. " stars, " .
  47. " level, " .
  48. " awaken " .
  49. "FROM monster_collection " .
  50. "WHERE id = $id; ";
  51. $q = $this->db->query($s);
  52. $set = false;
  53. $r = $q->fetchArray(SQLITE3_ASSOC);
  54. if ($r){
  55. $this->id = $r["id"];
  56. $this->stars = $r["stars"];
  57. $this->level = $r["level"];
  58. $this->awaken = $r["awaken"];
  59. $this->monster = new Monster($this->db, $r["monster"]);
  60. }
  61. }
  62. }
  63. ?>