Record.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. $s = "
  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. error_log($s);
  89. $q = $db->query($s);
  90. $r = $q->fetchArray(SQLITE3_ASSOC);
  91. $this->uid = $r["uid"];
  92. $this->area = new K_Area($r["area"], $r["area_type"]);
  93. $this->stage = $r["stage"];
  94. $this->time = $r["time"];
  95. $this->score = $r["score"];
  96. $this->rank = $r["rank"];
  97. $s = "
  98. SELECT
  99. unit,
  100. k_unit,
  101. (SELECT count(id) FROM unit WHERE unit.id = record_party.unit) AS owned,
  102. leader,
  103. front
  104. FROM record_party
  105. WHERE
  106. uid = $uid AND
  107. area_type = $area_type AND
  108. area = $area
  109. ORDER BY
  110. front DESC,
  111. leader DESC;
  112. ";
  113. $q = $db->query($s);
  114. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  115. if ($r["owned"] > 0){
  116. array_push($this->party, new Unit($r["unit"], false));
  117. }
  118. else{
  119. array_push($this->party, new K_Unit($r["k_unit"], false));
  120. }
  121. if ($r["leader"] == 1){
  122. $this->leader = $r["unit"];
  123. }
  124. if ($r["front"] == 1){
  125. array_push($this->frontline, $r["unit"]);
  126. }
  127. }
  128. }
  129. }
  130. ?>