| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- require_once($path["entity"] . "Entity.php");
- /**
- * Building.
- *
- * Represents an object from the table 'k_building'.
- */
- class K_Building extends Entity{
- /**
- * Building identifier.
- */
- public $id;
- /**
- * Building name.
- */
- public $name;
- /**
- * Building description.
- */
- public $description;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * building, populating it and it's items.
- *
- * @param SQLite3 $db Connection to the database.
- * @param int $id Building identifier.
- */
- public function __construct($db, $id){
- global $path;
- parent::__construct($db);
- $s =
- "SELECT " .
- " id, " .
- " name, " .
- " description " .
- "FROM k_building " .
- "WHERE id = $id; ";
- $q = $this->db->query($s);
- $r = $q->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->name = $r["name"];
- $this->description = $r["description"];
- }
- }
- /**
- * Gets the path to the building image. The image must be in the
- * img/building/ directory, and its name must be the monster id,
- * padded with '0' to 4 digites, and the extension must be '.png'.
- *
- * @return path to the image, or a path to a fixed unknown image if it
- * doesn't exist.
- */
- public function get_image(){
- global $base_dir;
- global $path;
- if (file_exists($base_dir . "img/building/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
- return $path["img"]["building"] . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
- }
- else{
- return $path["img"]["root"] . "unknown.png";
- }
- }
- }
- ?>
|