telvero_whatson_talpa/api/get_next_start_time.php

38 lines
904 B
PHP

<?php
/**
* API Endpoint: Get Next Start Time
* Calculates the next available start time based on existing transmissions
*/
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../helpers.php';
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
header('Content-Type: application/json');
try {
$db = getDbConnection();
$date = $_GET['date'] ?? date('Y-m-d');
$channel = $_GET['channel'] ?? 'SBS9';
$requestedTime = $_GET['requested_time'] ?? null;
// Get next start time using helper function
$nextStartTime = calculateNextStartTime($db, $date, $channel, $requestedTime);
jsonResponse([
'next_start_time' => $nextStartTime,
'date' => $date,
'channel' => $channel
]);
} catch (Exception $e) {
jsonResponse([
'error' => $e->getMessage()
], 500);
}