Team.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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,
  58. stage
  59. FROM team
  60. WHERE id = '$id';
  61. ";
  62. $q = $this->db->query($s);
  63. $r = $q->fetchArray(SQLITE3_ASSOC);
  64. $this->uid = $r["uid"];
  65. $this->id = $r["id"];
  66. $this->name = $r["name"];
  67. $this->description = $r["description"];
  68. $this->area = new K_Area($this->db, $r["area"]);
  69. $this->stage = $r["stage"];
  70. if ($complete){
  71. $s = "
  72. SELECT unit
  73. FROM team_unit
  74. WHERE team = '$id';
  75. ";
  76. $q = $this->db->query($s);
  77. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  78. array_push($this->skill_levels, $r["level"]);
  79. }
  80. }
  81. }
  82. }
  83. ?>