commit 3168b17ed9a062dd7cf9cd8284cef41dd574ba33 Author: Chimo Date: Tue Jul 16 18:24:27 2019 -0400 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9173bc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +private/config.php diff --git a/private/config.dist.php b/private/config.dist.php new file mode 100644 index 0000000..3516ca6 --- /dev/null +++ b/private/config.dist.php @@ -0,0 +1,10 @@ + '', + 'dbUser' => '', + 'dbPassword' => '', + 'dbName' => '', + 'timezone' => '' +]; + diff --git a/public/api/index.php b/public/api/index.php new file mode 100644 index 0000000..95c3852 --- /dev/null +++ b/public/api/index.php @@ -0,0 +1,97 @@ +prepare($query); + +$agency = $_GET['agency']; +$statement->execute(array(':agencyId' => $agency)); + +$row = $statement->fetch(); +$timezone = $row['agency_timezone']; +date_default_timezone_set($timezone); + +// Get current date/time +$d = explode('%', date('Y-m-d%H:i')); +$date = $d[0]; +$time = $d[1]; + +// Stop id +$stop = $_GET['stop']; + +// Based on: https://stackoverflow.com/a/51455985 +$query = <<= :time + ORDER BY tr.route_id, st.departure_time +) Q +ORDER BY route_short_name, service_id, departure_time +LIMIT 3 OFFSET 0; +SQL; + +// TODO: Error handling from here down + +$statement = $dbh->prepare($query); + +$statement->bindParam(':stopId', $stop, PDO::PARAM_STR); +$statement->bindParam(':date', $date, PDO::PARAM_STR); +$statement->bindParam(':time', $time, PDO::PARAM_STR); + +$statement->execute(); + +$rows = $statement->fetchAll(); + +error_log(print_r($rows, true)); + +$results = []; + +foreach ($rows as $row) { + $results[] = $row['departure_time']; +} + +// convert results to json +$json = json_encode($results); + +header('Content-Type: application/json'); +echo $json; +