 <?php
    /**
     * User profile page file.
     *
     * Provides a class with all the properties and methods to display the page.
     *
     * @category Page
     */

    /**
     * Require dependent files if not present.
     */
    require_once(PATH::PAGE . "Page.php");


    /**
     * User profile page model.
     *
     * @category Page
     */
    class Profile_Page extends Page{

        /**
         * @var string Player name.
         */
        public $name;

        /**
         * @var string Player email.
         */
        public $mail;

        /**
         * @var string Player API key.
         */
        public $api_key;

        /**
         * Constructor.
         *
         * Retrieves the data and initializes the variables.
         *
         * @param resource $db Connection to the database.
         * @global int Player ID.
         */
        public function __construct($db){
            global $UID;
            parent::__construct($db);
            $this->view = PATH::VIEW . "profile.php";
            $s = "
              SELECT
                name,
                mail,
                api_key
              FROM player
              WHERE uid = '$UID';
            ";
            $q = $this->db->query($s);
            if ($r = $q->fetchArray(SQLITE3_ASSOC)){
                $this->name = $r["name"];
                $this->mail = $r["mail"];
                $this->api_key = $r["api_key"];
            }
            $this->title = $this->name ." - SWDB";
            $this->description = $this->name . " user profile";
            $this->canonical = URL::BASE . "profile/";
        }

    }
?>

