Record.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 . "K_Unit.php");
  15. require_once(PATH::ENTITY . "K_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 $uid;
  28. /**
  29. * @var K_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[]|\K_Unit[] Uits used.
  50. * If the unit is still owned, it will be a instance of Unit.
  51. * If not, it will be a instance of K_Unit.
  52. */
  53. public $party = [];
  54. /**
  55. * @var int ID of the leader unit.
  56. */
  57. public $leader;
  58. /**
  59. * @var int[] List of IDs of the frontline units.
  60. */
  61. public $frontline = [];
  62. /**
  63. * Constructor.
  64. *
  65. * Searches the database and retrieves the information about the
  66. * run, populating it and it's items.
  67. *
  68. * @param int $id Run identifier.
  69. * @global resource Database connection.
  70. */
  71. public function __construct($uid, $area_type, $area){
  72. global $db;
  73. $statement = $db->prepare("
  74. SELECT
  75. uid,
  76. area_type,
  77. area,
  78. stage,
  79. time,
  80. score,
  81. rank
  82. FROM record
  83. WHERE
  84. uid = :uid AND
  85. area_type = :area_type AND
  86. area = :area;
  87. ");
  88. $statement->bindValue(':uid', $uid, 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->uid = $r["uid"];
  94. $this->area = new K_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 = $db->prepare("
  100. SELECT
  101. unit,
  102. k_unit,
  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. uid = :uid AND
  109. area_type = :area_type AND
  110. area = :area
  111. ORDER BY
  112. front DESC,
  113. leader DESC;
  114. ");
  115. $statement->bindValue(':uid', $uid, 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 K_Unit($r["k_unit"], 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. ?>