| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /**
- * Team entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "K_Area.php");
- require_once(PATH::ENTITY . "Unit.php");
- /**
- * A Team.
- *
- * Represents an object from the table 'unit'.
- *
- * @category Entity
- */
- class Team extends Entity{
- /**
- * @var int Owner identifier.
- */
- public $uid;
- /**
- * @var int Team identifier.
- */
- public $id;
- /**
- * @var string Team name.
- */
- public $name;
- /**
- * @var string Team description.
- */
- public $description;
- /**
- * @var \Unit[] Units in the team.
- */
- public $unit = [];
- /**
- * @var int ID of the leader unit.
- */
- public $leader;
- /**
- * @var int[] List of IDs of the frontline units.
- */
- public $frontline = [];
- /**
- * @var Area Area the team is designed for.
- */
- public $area;
- /**
- * @var int Stage the team is designed for. It can be null.
- */
- public $stage;
- /**
- * @var int difficulty the team is designed for. It can be null.
- *
- * @see DIFFICULTY_ID
- */
- public $difficulty;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * monster, populating it and it's items.
- *
- * @param int $id Monster identifier.
- * @param bool $complete If false, it won't load the units.
- * @global resource Database connection.
- */
- public function __construct($id, $complete = true){
- global $db;
- $s = "
- SELECT
- uid,
- id,
- name,
- description,
- area_type,
- area,
- stage,
- difficulty
- FROM team
- WHERE id = '$id';
- ";
- $q = $db->query($s);
- $r = $q->fetchArray(SQLITE3_ASSOC);
- $this->uid = $r["uid"];
- $this->id = $r["id"];
- $this->name = HTML::e($r["name"]);
- $this->description = HTML::e($r["description"]);
- $this->area = new K_Area($r["area"], $r["area_type"]);
- $this->stage = $r["stage"];
- if ($complete){
- $s = "
- SELECT
- unit,
- leader,
- front
- FROM team_unit
- WHERE team = '$id'
- ORDER BY
- front DESC,
- leader DESC;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->unit, new Unit($r["unit"], false));
- if ($r["leader"] == 1){
- $this->leader = $r["unit"];
- }
- if ($r["front"] == 1){
- array_push($this->frontline, $r["unit"]);
- }
- }
- }
- }
- }
- ?>
|