
<?php

/**
* Created by : Julien Dubois.
* Version : 2;
* Update date : 13.05.2022
*/

require_once("../Workers/Connexion.php");
require_once("SessionManager.php");
class ProfileDBManager
{

    private $connexion;

    /**
     * constructeur permettant de prendre l'instance de la connection a la base de donnée
     */
    public function __construct()
    {
        $this->connexion = Connexion::getInstance();
    }

    /**
     * Fonction permettant de recevoir les détails de l'utilisateur tiré de la base de donnée dans un format XML 
     */
    function getUserDetails($username)
    {
        $query = "select * from t_user where pseudo=:pseudo";
        $params = array('pseudo' => $username);
        $currentuser = $this->connexion->selectSingleQuery($query, $params);
        $pk = $currentuser['PK_User'];
        $query2 =  "select PFK_Rune from tr_user_rune where PFK_User=:pk";
        $params2 = array('pk' => $pk);
        $userrunes = $this->connexion->selectQuery($query2, $params2);
        $runeLianes = "false";
        $runeTP = "false";
        $runeRam = "false";
        $runeSpider = "false";

        foreach ($userrunes as $rune) {
            switch ($rune[0]) {
                case 1:
                    $runeLianes = "true";
                    break;
                case 2:
                    $runeTP = "true";
                    break;
                case 3:
                    $runeRam = "true";
                    break;
                case 4:
                    $runeSpider = "true";
                    break;

                default:
                    break;
            }
        }

        $userXML = "<user>" .
            "<pseudo>" .
            $currentuser['pseudo'] .
            "</pseudo>" .
            "<nom>" .
            $currentuser['nom'] .
            "</nom>" .
            "<prenom>" .
            $currentuser['prenom'] .
            "</prenom>" .
            "<bosscells>" .
            $currentuser['bossCells'] .
            "</bosscells>" .
            "<fkDLC>" .
            $currentuser['FK_DLC'] .
            "</fkDLC>". 
            "<runeLianes>". 
            $runeLianes. 
            "</runeLianes>".
            "<runeTP>".
            $runeTP. 
            "</runeTP>".
            "<runeRam>". 
            $runeRam.
            "</runeRam>". 
            "<runeSpider>". 
            $runeSpider.
            "</runeSpider>". 
            "</user>";
        return $userXML;
    }
}



























?>
