| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- /**
- * Record run entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Unit.php");
- require_once(PATH::ENTITY . "K_Unit.php");
- require_once(PATH::ENTITY . "K_Area.php");
- /**
- * A record run.
- *
- * Represents an object from the table 'record'.
- *
- * @category Entity
- */
- class Record extends Entity{
- /**
- * @var int Player identifier.
- */
- public $uid;
- /**
- * @var K_Area Area.
- */
- public $area;
- /**
- * @var int Stage.
- */
- public $stage;
- /**
- * @var int Clear time, milliseconds.
- */
- public $time;
- /**
- * @var int Score in battles that are rated (WB, rift dungeons...).
- */
- public $score;
- /**
- * @var String Rank in battles that are rated (WB, rift dungeons...).
- */
- public $rank;
- /**
- * @var \Unit[]|\K_Unit[] Uits used.
- * If the unit is still owned, it will be a instance of Unit.
- * If not, it will be a instance of K_Unit.
- */
- public $party = [];
- /**
- * @var int ID of the leader unit.
- */
- public $leader;
- /**
- * @var int[] List of IDs of the frontline units.
- */
- public $frontline = [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * run, populating it and it's items.
- *
- * @param int $id Run identifier.
- * @global resource Database connection.
- */
- public function __construct($uid, $area_type, $area){
- global $db;
- $statement = $db->prepare("
- SELECT
- uid,
- area_type,
- area,
- stage,
- time,
- score,
- rank
- FROM record
- WHERE
- uid = :uid AND
- area_type = :area_type AND
- area = :area;
- ");
- $statement->bindValue(':uid', $uid, SQLITE3_INTEGER);
- $statement->bindValue(':area_type', $area_type, SQLITE3_INTEGER);
- $statement->bindValue(':area', $area, SQLITE3_INTEGER);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->uid = $r["uid"];
- $this->area = new K_Area($r["area"], $r["area_type"]);
- $this->stage = $r["stage"];
- $this->time = $r["time"];
- $this->score = $r["score"];
- $this->rank = $r["rank"];
- $statement = $db->prepare("
- SELECT
- unit,
- k_unit,
- (SELECT count(id) FROM unit WHERE unit.id = record_party.unit) AS owned,
- leader,
- front
- FROM record_party
- WHERE
- uid = :uid AND
- area_type = :area_type AND
- area = :area
- ORDER BY
- front DESC,
- leader DESC;
- ");
- $statement->bindValue(':uid', $uid, SQLITE3_INTEGER);
- $statement->bindValue(':area_type', $area_type, SQLITE3_INTEGER);
- $statement->bindValue(':area', $area, SQLITE3_INTEGER);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- if ($r["owned"] > 0){
- array_push($this->party, new Unit($r["unit"], false));
- }
- else{
- array_push($this->party, new K_Unit($r["k_unit"], false));
- }
- if ($r["leader"] == 1){
- $this->leader = $r["unit"];
- }
- if ($r["front"] == 1){
- array_push($this->frontline, $r["unit"]);
- }
- }
- }
- }
- }
- ?>
|