Sixtens hemsida Uppgifter Blogg Om

VED House bokningssystem

Gå till sida

Källkod

api/

database.php

api.php

ved/

monthBookingData.php

openingHoursException.php

bookingData.php

dayTimeframes.php

bookings.php

admin/

revokeToken.php

authorization.php

login.php

modules/

vedDatabase.php

utility.php

gyar/

log.php

auth/

revokeToken.php

authorization.php

login.php

station/

settings.php

log.php

modules/

gyarDatabase.php

databaseConnection.php

database.php

utility.php

credentials.json

weather/

latest.php

old.php

admin/

index.html

changeTimetable.html

login.html

js/

login.js

modules.js

admin.js

header.js

changeTimetable.js

cron/

vedClearExpiredTokens.php

api/gyar/weather/old.php

1 lines
<?php
# latest.php
# API endpoint
# Fil för att hämta äldre väderdata från en viss mätpunkt.

require_once "gyar/modules/utility.php";

# Hämtar äldre väderdata på en viss punkt.
$functionGET = function () {
    require 
"gyar/modules/database.php";

    
$pointData $db->query(
        
"SELECT mp.latitude, mp.longitude FROM measuringPoint mp WHERE mp.pointId=:pointId;",
        [
            
"pointId" => $_GET["pointId"]
        ]
    );
    
$intervalData $db->queryAll(
        
"SELECT UNIX_TIMESTAMP(spt.timestamp) AS 'timestamp', wd.temperature, wd.humidity, wd.airPressure, wd.downfall, wd.windSpeed, wd.windDirection FROM measuringPoint mp JOIN stationPointInstance sp ON sp.pointId = mp.pointId JOIN weatherStation ws on sp.stationId = ws.stationId JOIN stationPointTimeData spt ON spt.stationPointInstanceId = sp.stationPointInstanceId JOIN weatherData wd ON wd.stationPointDataId = spt.stationPointDataId WHERE mp.pointId=:pointId AND spt.timestamp BETWEEN :date1 AND :date2 ORDER BY spt.timestamp ASC;",
        [
            
"pointId" => $_GET["pointId"],
            
"date1" => $_GET["date1"],
            
"date2" => $_GET["date2"]
        ]
    );

    
$returnData = [
        
"latitude" => $pointData["latitude"],
        
"longitude" => $pointData["longitude"],
        
"data" => []
    ];
    foreach (
$intervalData as $dateData) {
        
array_push($returnData["data"], [
            
"timestamp" => $dateData["timestamp"],
            
"data" => [
                
"temperature" => $dateData["temperature"],
                
"humidity" => $dateData["humidity"],
                
"airPressure" => $dateData["airPressure"],
                
"downfall" => $dateData["downfall"],
                
"windSpeed" => $dateData["windSpeed"],
                
"windDirection" => $dateData["windDirection"],
            ],
        ]);
    }

    return 
$returnData;
};

$api = new APIEndpoint();

$httpGET = new APIMethod("GET"$functionGET);
$httpGET->setRequiredGETParameters(["pointId""date1""date2"]);
$api->addMethod($httpGET);

return 
$api;
?>