| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * Transformation 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 . "K_Skill.php");
- require_once(PATH::ENTITY . "K_Leader_Skill.php");
- require_once(PATH::ENTITY . "K_Source.php");
- /**
- * Unit transformation.
- *
- * Represents an object from the table 'k_unit_transformation'.
- *
- * @category Entity
- */
- class K_Unit_Transformation extends Entity{
- /**
- * @var int Transformed unit identifier.
- */
- public $id;
- /**
- * @var int Transformed unit family id.
- */
- public $family;
- /**
- * @var int ID of the unit that transformes into this.
- */
- public $unit;
- /**
- * @var \K_Skill[] Skills in the transformed form.
- */
- public $skill = [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * trnsformed unit, populating it and it's items.
- *
- * @param int $id Transformed unit identifier.
- * @global resource Database connection.
- */
- public function __construct($id){
- global $db;
- $statement = $db->prepare("
- SELECT
- id,
- family,
- unit
- FROM k_unit_transformation
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->family = $r["family"];
- $this->unit = $r["unit"];
- $this->load_skills();
- }
- }
- /**
- * Loads the information about the unit skills in the transformed form.
- *
- * @global resource Database connection.
- */
- private function load_skills(){
- global $db;
- $this->skill = [];
- $s = "
- SELECT skill
- FROM
- k_skill,
- k_unit_skill
- WHERE
- id = skill AND
- unit = " . $this->id . "
- ORDER BY slot;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->skill, new K_Skill($r["skill"]));
- }
- }
- /**
- * Gets the path to the unit image. The image must be in the
- * img/unit/ directory, and it's name must be the unit id,
- * padded with '0' to 8 digits, and the extension must be '.png'.
- *
- * @return string Image URL, or a fixed unknown image.
- */
- public function get_image(){
- return APPLICATION::img("UNIT", $this->id);
- }
- }
- ?>
|