<?php
    /**
     * Decoration 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_Decoration.php");

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

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

        /**
         * @var K_Decoration Base decoration.
         */
        public $decoration;

        /**
         * @var int decoration level.
         */
        public $level;

        /**
         * Constructor.
         *
         * Searches the database and retrieves the information about the
         * decoration, 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,
                  decoration,
                  level
                FROM decoration
                WHERE decoration = $id;
            ";
            $q = $this->db->query($s);
            $r = $q->fetchArray(SQLITE3_ASSOC);
            $this->uid = $r["uid"];
            $this->decoration = new K_Decoration($this->db, $r["decoration"]);
            $this->level = $r["level"];
        }
    }
?>
