| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * Building view page file.
- *
- * Provides a class with all the properties and methods to display the page.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
- * @package SWDB
- */
- require_once(PATH::PAGE . "Page.php");
- require_once(PATH::ENTITY . "Unit.php");
- /**
- * Building view page model.
- *
- * @category Page
- */
- class Building_Page extends Page{
- /**
- * @var Buildable|Decorative Selected building.
- */
- private $building;
- /**
- * @var bool Checks if the selected item is a Decorative.
- */
- private $type_decorative = false;
- /**
- * Constructor.
- *
- * Retrieves the data and initializes the variables.
- *
- * @param string $id Selected unit id
- */
- public function __construct($id){
- parent::__construct();
- $this->set_public(true);
- $this->set_view("building.php");
-
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- type
- FROM (
- SELECT id, 'buildable' AS type from buildable
- UNION
- SELECT id, 'decorative' as type FROM decorative
- )
- WHERE id = :id;
- ");
- $statement->bindValue(":id", $id, SQLITE3_INTEGER);
-
- $result = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if (! $result){
- $this->set_code(404);
- $this->set_message("Building not found");
- }
- else{
- if ($result["type"] == "buildable"){
- $this->building = new Buildable($id);
- $this->type_decorative = false;
- }
- elseif ($result["type"] == "decorative"){
- $this->building = new Decorative($id);
- $this->type_decorative = true;
- }
- if ($this->building == null || $this->building->get_id() == null){
- $this->set_code(404);
- $this->set_message("Building not found");
- }
- else{
- $this->set_code(200);
- $this->set_message("OK");
- $this->set_title($this->building->get_name());
- $this->set_description($this->building->get_name() . " details");
- $this->set_canonical("buildings/" . $this->building->get_id());
- $this->add_css("building.css");
- }
- }
- }
- /**
- * Retrieves the selected building.
- *
- * @return Buildable|Decorative Selected building.
- */
- public function get_building(){
- return $this->building;
- }
-
- /**
- * Checks if the selcted item is a decorative.
- *
- * @return bool True if Decorative, false if Buildable.
- */
- public function is_decorative(){
- return $this->type_decorative;
- }
- /**
- * Checks if the selcted item is a buildable.
- *
- * @return bool True if Buildable, false if Decorative.
- */
- public function is_buildable(){
- return (! $this->type_decorative);
- }
- }
|