Record.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Record run entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. /**
  10. * Require dependent entities if not present.
  11. */
  12. require_once(PATH::ENTITY . "Entity.php");
  13. require_once(PATH::ENTITY . "Unit.php");
  14. require_once(PATH::ENTITY . "Monster.php");
  15. require_once(PATH::ENTITY . "Area.php");
  16. /**
  17. * A record run.
  18. *
  19. * Represents an object from the table 'record'.
  20. *
  21. * @category Entity
  22. */
  23. class Record extends Entity{
  24. /**
  25. * @var int Player identifier.
  26. */
  27. public $player;
  28. /**
  29. * @var Area Area.
  30. */
  31. public $area;
  32. /**
  33. * @var int Stage.
  34. */
  35. public $stage;
  36. /**
  37. * @var int Clear time, milliseconds.
  38. */
  39. public $time;
  40. /**
  41. * @var int Score in battles that are rated (WB, rift dungeons...).
  42. */
  43. public $score;
  44. /**
  45. * @var String Rank in battles that are rated (WB, rift dungeons...).
  46. */
  47. public $rank;
  48. /**
  49. * @var \Unit[]|\Monster[] Units or monsters used.
  50. * If the unit is still owned, it will be a instance of Unit.
  51. * If not, it will be a instance of Monster.
  52. */
  53. public $party = [];
  54. /**
  55. * @var int ID of the leader unit or monster.
  56. */
  57. public $leader;
  58. /**
  59. * @var int[] List of IDs of the frontline units or monsters.
  60. */
  61. public $frontline = [];
  62. /**
  63. * Constructor.
  64. *
  65. * Searches the database and retrieves the information about the
  66. * record, populating it and it's items.
  67. *
  68. * @param int $player_id Selected player identifier.
  69. * @param int $area_type Area type identifier.
  70. * @param int $area Area identifier.
  71. * @global resource Database connection.
  72. */
  73. public function __construct($player_id, $area_type, $area){
  74. global $db;
  75. $statement = $db->prepare("
  76. SELECT
  77. player,
  78. area_type,
  79. area,
  80. stage,
  81. time,
  82. score,
  83. rank
  84. FROM record
  85. WHERE
  86. player = :player AND
  87. area_type = :area_type AND
  88. area = :area;
  89. ");
  90. $statement->bindValue(':player', $player_, SQLITE3_TEXT);
  91. $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
  92. $statement->bindValue(':area', $area, SQLITE3_TEXT);
  93. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  94. if ($r){
  95. $this->player = $r["player"];
  96. $this->area = new Area($r["area"], $r["area_type"]);
  97. $this->stage = $r["stage"];
  98. $this->time = $r["time"];
  99. $this->score = $r["score"];
  100. $this->rank = $r["rank"];
  101. $statement = $db->prepare("
  102. SELECT
  103. unit,
  104. monster,
  105. (SELECT count(id) FROM unit WHERE unit.id = record_party.unit) AS owned,
  106. leader,
  107. front
  108. FROM record_party
  109. WHERE
  110. player = :player AND
  111. area_type = :area_type AND
  112. area = :area
  113. ORDER BY
  114. front DESC,
  115. leader DESC;
  116. ");
  117. $statement->bindValue(':player', $player, SQLITE3_TEXT);
  118. $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
  119. $statement->bindValue(':area', $area, SQLITE3_TEXT);
  120. $q = $statement->execute();
  121. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  122. if ($r["owned"] > 0){
  123. array_push($this->party, new Unit($r["unit"], false));
  124. }
  125. else{
  126. array_push($this->party, new Monster($r["monster"], false));
  127. }
  128. if ($r["leader"] == 1){
  129. $this->leader = $r["unit"];
  130. }
  131. if ($r["front"] == 1){
  132. array_push($this->frontline, $r["unit"]);
  133. }
  134. }
  135. }
  136. }
  137. }
  138. ?>