Record.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. */
  72. public function __construct($player_id, $area_type, $area){
  73. $statement = get_context()->get_db()->prepare("
  74. SELECT
  75. player,
  76. area_type,
  77. area,
  78. stage,
  79. time,
  80. score,
  81. rank
  82. FROM record
  83. WHERE
  84. player = :player AND
  85. area_type = :area_type AND
  86. area = :area;
  87. ");
  88. $statement->bindValue(':player', $player_id, SQLITE3_TEXT);
  89. $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
  90. $statement->bindValue(':area', $area, SQLITE3_TEXT);
  91. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  92. if ($r){
  93. $this->player = $r["player"];
  94. $this->area = new Area($r["area"], $r["area_type"]);
  95. $this->stage = $r["stage"];
  96. $this->time = $r["time"];
  97. $this->score = $r["score"];
  98. $this->rank = $r["rank"];
  99. $statement = get_context()->get_db()->prepare("
  100. SELECT
  101. unit,
  102. monster,
  103. (SELECT count(id) FROM unit WHERE unit.id = record_party.unit) AS owned,
  104. leader,
  105. front
  106. FROM record_party
  107. WHERE
  108. player = :player AND
  109. area_type = :area_type AND
  110. area = :area
  111. ORDER BY
  112. front DESC,
  113. leader DESC;
  114. ");
  115. $statement->bindValue(':player', $player_id, SQLITE3_TEXT);
  116. $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
  117. $statement->bindValue(':area', $area, SQLITE3_TEXT);
  118. $q = $statement->execute();
  119. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  120. if ($r["owned"] > 0){
  121. array_push($this->party, new Unit($r["unit"], false));
  122. }
  123. else{
  124. array_push($this->party, new Monster($r["monster"], false));
  125. }
  126. if ($r["leader"] == 1){
  127. $this->leader = $r["unit"];
  128. }
  129. if ($r["front"] == 1){
  130. array_push($this->frontline, $r["unit"]);
  131. }
  132. }
  133. }
  134. }
  135. }
  136. ?>