<?php

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

/**
 * Description of EeSsManager
 *
 * @author pc
 */
include_once "server/lib/mod_dbm/package.dbm.php";

class EeSsManager {

    private $dao;

    function __construct() {
        $this->dao = new dbObject();
    }

    public function getCloserEESS($lat, $lng) {
        $q = sprintf("SELECT * from ee_ss WHERE lat IS NOT NULL AND lng IS NOT  NULL ORDER BY POW(lat-(%s),2)+POW(lng -(%s),2) LIMIT 0,1", $lat, $lng);
        $res = $this->dao->fetchQuery($q);
        return $res[0];
    }

    public function getEESSCoords($id) {
        $q = sprintf("SELECT lat,lng FROM ee_ss WHERE id_ee_ss = %d", $id);
      
        $returnValue = false;
        if ($res = $this->dao->fetchQuery($q)) {
            $returnValue['lat'] = $res[0]['lat'];
            $returnValue['lng'] = $res[0]['lng'];
        }
        return $returnValue;
    }

}
