<?php

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

/**
 * Description of TempHumManager
 *
 * @author pc
 */
class TempHumManager {
    private $log_id;
    private $sub_message;
    private $machine_id;
    private $sensor_id;
    private $temp;
    private $hr;
    private $battery;
    private $is_alert;
    private $lat;
    private $lng;
    private $gps_timestamp;

    
     public static function retrieveRange($machineId, $fromTs, $toTs) {
        // Conexión a la base de datos
        $dao = new dbObject();
        $stmt = $dao->connection->prepare("SELECT * FROM log_th WHERE machine_id = ? AND gps_timestamp >= ? AND gps_timestamp <= ? ORDER BY gps_timestamp");

        // Establecimiento de los parámetros de la consulta
        $stmt->bind_param("iii", $machineId, $fromTs, $toTs);

        // Ejecución de la consulta
        $stmt->execute();

        // Obtención del resultado
        $result = $stmt->get_result();

        // Transformación del resultado en un array de objetos LogTh
        $thLog = array();
        while ($row = $result->fetch_assoc()) {
            /*
            $log = new LogTh();
            $log->setLogId($row['log_id']);
            $log->setSubMessage($row['sub_message']);
            $log->setMachineId($row['machine_id']);
            $log->setSensorId($row['sensor_id']);
            $log->setTemp($row['temp']);
            $log->setHr($row['hr']);
            $log->setBattery($row['battery']);
            $log->setIsAlert($row['is_alert']);
            $log->setLat($row['lat']);
            $log->setLng($row['lng']);
            $log->setGpsTimestamp($row['gps_timestamp']);
            
             */
            $thLog[] = $row;
        }

        // Cierre de la conexión y retorno del resultado
        $stmt->close();
        return $thLog;
    }
    
    
    public function getLogId() {
        return $this->log_id;
    }

    public function setLogId($log_id) {
        $this->log_id = $log_id;
    }

    public function getSubMessage() {
        return $this->sub_message;
    }

    public function setSubMessage($sub_message) {
        $this->sub_message = $sub_message;
    }

    public function getMachineId() {
        return $this->machine_id;
    }

    public function setMachineId($machine_id) {
        $this->machine_id = $machine_id;
    }

    public function getSensorId() {
        return $this->sensor_id;
    }

    public function setSensorId($sensor_id) {
        $this->sensor_id = $sensor_id;
    }

    public function getTemp() {
        return $this->temp;
    }

    public function setTemp($temp) {
        $this->temp = $temp;
    }

    public function getHr() {
        return $this->hr;
    }

    public function setHr($hr) {
        $this->hr = $hr;
    }

    public function getBattery() {
        return $this->battery;
    }

    public function setBattery($battery) {
        $this->battery = $battery;
    }

    public function getIsAlert() {
        return $this->is_alert;
    }

    public function setIsAlert($is_alert) {
        $this->is_alert = $is_alert;
    }

    public function getLat() {
        return $this->lat;
    }

    public function setLat($lat) {
        $this->lat = $lat;
    }

    public function getLng() {
        return $this->lng;
    }

    public function setLng($lng) {
        $this->lng = $lng;
    }

    public function getGpsTimestamp() {
        return $this->gps_timestamp;
    }

    public function setGpsTimestamp($gps_timestamp) {
        $this->gps_timestamp = $gps_timestamp;
    }
}

