Team.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Team 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 . "K_Area.php");
  13. require_once(PATH::ENTITY . "Unit.php");
  14. /**
  15. * A Team.
  16. *
  17. * Represents an object from the table 'unit'.
  18. *
  19. * @category Entity
  20. */
  21. class Team extends Entity{
  22. /**
  23. * @var int Owner identifier.
  24. */
  25. public $uid;
  26. /**
  27. * @var int Team identifier.
  28. */
  29. public $id;
  30. /**
  31. * @var string Team name.
  32. */
  33. public $name;
  34. /**
  35. * @var string Team description.
  36. */
  37. public $description;
  38. /**
  39. * @var \Unit[] Units in the team.
  40. */
  41. public $unit = [];
  42. /**
  43. * @var int ID of the leader unit.
  44. */
  45. public $leader;
  46. /**
  47. * @var int[] List of IDs of the frontline units.
  48. */
  49. public $frontline = [];
  50. /**
  51. * @var \K_Area Area the team is designed for.
  52. */
  53. public $area;
  54. /**
  55. * @var int Stage the team is designed for. It can be null.
  56. */
  57. public $stage;
  58. /**
  59. * @var int difficulty the team is designed for. It can be null.
  60. *
  61. * @see DIFFICULTY_ID
  62. */
  63. public $difficulty;
  64. /**
  65. * @var int Team score for the optmizer
  66. */
  67. public $score;
  68. /**
  69. * Constructor.
  70. *
  71. * Searches the database and retrieves the information about the
  72. * monster, populating it and it's items.
  73. *
  74. * @param int $id Monster identifier.
  75. * @param bool $complete If false, it won't load the units.
  76. * @global resource Database connection.
  77. */
  78. public function __construct($id, $complete = true){
  79. global $db;
  80. $statement = $db->prepare("
  81. SELECT
  82. uid,
  83. id,
  84. name,
  85. description,
  86. area_type,
  87. area,
  88. stage,
  89. difficulty,
  90. score
  91. FROM team
  92. WHERE id = :id;
  93. ");
  94. $statement->bindValue(':id', $id, SQLITE3_INTEGER);
  95. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  96. if ($r){
  97. $this->uid = $r["uid"];
  98. $this->id = $r["id"];
  99. $this->name = HTML::e($r["name"]);
  100. $this->description = HTML::e($r["description"]);
  101. $this->area = new K_Area($r["area"], $r["area_type"]);
  102. $this->stage = $r["stage"];
  103. $this->score = $r["score"];
  104. if ($complete){
  105. $statement = $db->prepare("
  106. SELECT
  107. unit,
  108. leader,
  109. front
  110. FROM team_unit
  111. WHERE team = :team
  112. ORDER BY
  113. front DESC,
  114. leader DESC;
  115. ");
  116. $statement->bindValue(':team', $this->id, SQLITE3_INTEGER);
  117. $q = $statement->execute();
  118. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  119. array_push($this->unit, new Unit($r["unit"], false));
  120. if ($r["leader"] == 1){
  121. $this->leader = $r["unit"];
  122. }
  123. if ($r["front"] == 1){
  124. array_push($this->frontline, $r["unit"]);
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }
  131. ?>