<?php

    /**
     * Building 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_Building.php");

    /**
     * A Building.
     *
     * Represents an object from the table 'building'.
     *
     * @category Entity
     */
    class Building extends Entity{

        /**
         * @var int Owner identifier.
         */
        public $uid;

        /**
         * @var K_Building Base building.
         */
        public $building;

        /**
         * @var int Gain per horu.
         */
        public $gain;

        /**
         * Constructor.
         *
         * Searches the database and retrieves the information about the
         * building, populating it and it's items.
         *
         * @param resource $db Connection to the database.
         * @param int $id Building identifier.
         */
        public function __construct($db, $id){
            parent::__construct($db);
            $s = "
                SELECT
                  uid,
                  building,
                  gain
                FROM building
                WHERE building = $id;
            ";
            $q = $this->db->query($s);
            $r = $q->fetchArray(SQLITE3_ASSOC);
            $this->uid = $r["uid"];
            $this->building = new K_Building($this->db, $r["building"]);
            $this->gain = $r["gain"];
        }
    }
?>
