<?php

    require_once($path["entity"] . "Entity.php");
    require_once($path["entity"] . "K_Building.php");


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

        /**
         * Owner identifier.
         */
        public $uid;

        /**
         * {@see K_Building}.
         */
        public $building;

        /**
         * I honestly don't know what the gin is.
         */
        public $gain;

        /**
         * 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
                  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"];
        }
    }
?>
