Team.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 Area Area the team is designed for.
  44. */
  45. public $area;
  46. /**
  47. * @var int Stage the team is designed for. It can be null.
  48. */
  49. public $stage;
  50. /**
  51. * @var int difficulty the team is designed for. It can be null.
  52. *
  53. * @see DIFFICULTY
  54. */
  55. public $difficulty;
  56. /**
  57. * Constructor.
  58. *
  59. * Searches the database and retrieves the information about the
  60. * monster, populating it and it's items.
  61. *
  62. * @param resource $db Connection to the database.
  63. * @param int $id Monster identifier.
  64. * @param bool $complete If false, it won't load the units.
  65. */
  66. public function __construct($db, $id, $complete = true){
  67. parent::__construct($db);
  68. $s = "
  69. SELECT
  70. uid,
  71. id,
  72. name,
  73. description,
  74. area_type,
  75. area,
  76. stage,
  77. difficulty
  78. FROM team
  79. WHERE id = '$id';
  80. ";
  81. $q = $this->db->query($s);
  82. $r = $q->fetchArray(SQLITE3_ASSOC);
  83. $this->uid = $r["uid"];
  84. $this->id = $r["id"];
  85. $this->name = HTML::e($r["name"]);
  86. $this->description = HTML::e($r["description"]);
  87. $this->area = new K_Area($this->db, $r["area"], $r["area_type"]);
  88. $this->stage = $r["stage"];
  89. if ($complete){
  90. $s = "
  91. SELECT unit
  92. FROM team_unit
  93. WHERE team = '$id';
  94. ";
  95. $q = $this->db->query($s);
  96. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  97. array_push($this->unit, new Unit($this->db, $r["unit"], false));
  98. }
  99. }
  100. }
  101. }
  102. ?>