Team.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 . "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's player identifier.
  24. */
  25. public $player;
  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 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. */
  77. public function __construct($id, $complete = true){
  78. $statement = get_context()->get_db()->prepare("
  79. SELECT
  80. player,
  81. id,
  82. name,
  83. description,
  84. area_type,
  85. area,
  86. stage,
  87. difficulty,
  88. score
  89. FROM team
  90. WHERE id = :id;
  91. ");
  92. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  93. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  94. if ($r){
  95. $this->player = $r["player"];
  96. $this->id = $r["id"];
  97. $this->name = HTML::e($r["name"]);
  98. $this->description = HTML::e($r["description"]);
  99. $this->area = new Area($r["area"], $r["area_type"]);
  100. $this->stage = $r["stage"];
  101. $this->score = $r["score"];
  102. if ($complete){
  103. $statement = get_context()->get_db()->prepare("
  104. SELECT
  105. unit,
  106. leader,
  107. front
  108. FROM team_unit
  109. WHERE team = :team
  110. ORDER BY
  111. front DESC,
  112. leader DESC;
  113. ");
  114. $statement->bindValue(':team', $this->id, SQLITE3_TEXT);
  115. $q = $statement->execute();
  116. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  117. array_push($this->unit, new Unit($r["unit"], false));
  118. if ($r["leader"] == 1){
  119. $this->leader = $r["unit"];
  120. }
  121. if ($r["front"] == 1){
  122. array_push($this->frontline, $r["unit"]);
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. ?>