<?php

class USettings {

    private $id;
    private $twofa;
    private $tor;
    private $news;
    private $user;

    function setId($id) {
        $this->id = $id;
    }

    function getId() {
        return $this->id;
    }

    function setTwofa($twofa) {
        $this->twofa = boolval($twofa);
    }

    function getTwofa() {
        return $this->twofa;
    }

    function setTor($tor) {
        $this->tor = boolval($tor);
    }

    function getTor() {
        return $this->tor;
    }

    function setNews($news) {
        $this->news = boolval($news);
    }

    function getNews() {
        return $this->news;
    }

    function setUser($user) {
        $this->user = $user;
    }

    function getUser() {
        return $this->user;
    }

    /**
     * Fetch the current user settings
     *
     * @param mysqli $link
     * @access public
     *
     * @return USettings or default on failure
     */
    public static function getSystemSettings($link, $user) {
        $result = mysqli_query($link, "select * from usettings WHERE `user` = '$user'");
        if (mysqli_num_rows($result) == 0) {
            $settings = new USettings();
            $settings->setNews(1);
            $settings->setTwofa(0);
            $settings->setTor(1);
            $settings->setUser($user);
            return $settings;
        }
        $settings = mysqli_fetch_object($result, USettings::class);
        return $settings;
    }

}
