Team.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. require_once($path["entity"] . "K_Area.php");
  3. require_once($path["entity"] . "Unit.php");
  4. /**
  5. * A Team.
  6. *
  7. * Represents an object from the table 'unit'.
  8. */
  9. class Team extends Entity{
  10. /**
  11. * Owner identifier.
  12. */
  13. public $uid;
  14. /**
  15. * Team identifier.
  16. */
  17. public $id;
  18. /**
  19. * Team name.
  20. */
  21. public $name;
  22. /**
  23. * Team description.
  24. */
  25. public $description;
  26. /**
  27. * List of {@see Unit}s in the team.
  28. */
  29. public $unit = [];
  30. /**
  31. * Area the team is designed for.
  32. */
  33. public $area;
  34. /**
  35. * Stage the team is designed for. It can be null.
  36. */
  37. public $stage;
  38. /**
  39. * Constructor.
  40. *
  41. * Searches the database and retrieves the information about the
  42. * monster, populating it and it's items.
  43. *
  44. * @param SQLite3 $db Connection to the database.
  45. * @param int $id Monster identifier.
  46. * @param complete If false, query only monster and k_monster.
  47. */
  48. public function __construct($db, $id, $complete = true){
  49. global $path;
  50. parent::__construct($db);
  51. $s = "
  52. SELECT
  53. uid,
  54. id,
  55. name,
  56. description,
  57. area_type,
  58. area,
  59. stage,
  60. difficulty
  61. FROM team
  62. WHERE id = '$id';
  63. ";
  64. $q = $this->db->query($s);
  65. $r = $q->fetchArray(SQLITE3_ASSOC);
  66. $this->uid = $r["uid"];
  67. $this->id = $r["id"];
  68. $this->name = $r["name"];
  69. $this->description = $r["description"];
  70. $this->area = new K_Area($this->db, $r["area"], $r["area_type"]);
  71. $this->stage = $r["stage"];
  72. if ($complete){
  73. $s = "
  74. SELECT unit
  75. FROM team_unit
  76. WHERE team = '$id';
  77. ";
  78. $q = $this->db->query($s);
  79. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  80. array_push($this->unit, new Unit($this->db, $r["unit"], false));
  81. }
  82. }
  83. }
  84. }
  85. ?>