<?php

/*
 * ROMAN DIGITAL - Autor: Américo Patetta
 */

/**
 * Description of SessionManager
 *
 * @author pc
 */
class SessionManager {

    //put your code here

    private $token;

    function __construct($token) {
        $this->token = $token;
    }

    public function getUserId() {
        $dao = new dbObject();
        $statement = $dao->connection->prepare("SELECT * FROM deliverys WHERE current_token = ?");
        $statement->bind_param("s", $this->token);
        $statement->execute();
        $result = $statement->get_result();
        if ($deliveryRow = $result->fetch_array(MYSQLI_ASSOC)) {
            $userId = $deliveryRow['id_delivery'];
        } else {
            $userId = null;
        }
        return $userId;
    }

    public function getDeliveryFromToken($token) {
        $dao = new dbObject();
        $statement = $dao->connection->prepare("SELECT * FROM deliverys WHERE current_token = ?");
        $statement->bind_param("s", $this->token);
        $statement->execute();
        $result = $statement->get_result();
        if ($deliveryRow = $result->fetch_array(MYSQLI_ASSOC)) {
            $userId = $deliveryRow['id_delivery'];
        } else {
            $userId = null;
        }
        return $userId;
    }

}
