Team.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 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. * Constructor.
  66. *
  67. * Searches the database and retrieves the information about the
  68. * monster, populating it and it's items.
  69. *
  70. * @param int $id Monster identifier.
  71. * @param bool $complete If false, it won't load the units.
  72. * @global resource Database connection.
  73. */
  74. public function __construct($id, $complete = true){
  75. global $db;
  76. $s = "
  77. SELECT
  78. uid,
  79. id,
  80. name,
  81. description,
  82. area_type,
  83. area,
  84. stage,
  85. difficulty
  86. FROM team
  87. WHERE id = '$id';
  88. ";
  89. $q = $db->query($s);
  90. $r = $q->fetchArray(SQLITE3_ASSOC);
  91. $this->uid = $r["uid"];
  92. $this->id = $r["id"];
  93. $this->name = HTML::e($r["name"]);
  94. $this->description = HTML::e($r["description"]);
  95. $this->area = new K_Area($r["area"], $r["area_type"]);
  96. $this->stage = $r["stage"];
  97. if ($complete){
  98. $s = "
  99. SELECT
  100. unit,
  101. leader,
  102. front
  103. FROM team_unit
  104. WHERE team = '$id'
  105. ORDER BY
  106. front DESC,
  107. leader DESC;
  108. ";
  109. $q = $db->query($s);
  110. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  111. array_push($this->unit, new Unit($r["unit"], false));
  112. if ($r["leader"] == 1){
  113. $this->leader = $r["unit"];
  114. }
  115. if ($r["front"] == 1){
  116. array_push($this->frontline, $r["unit"]);
  117. }
  118. }
  119. }
  120. }
  121. }
  122. ?>