feat(navigate) navigation available and most usefull features)
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
<div>
|
||||
<img src="/assets/lines/m.svg" width="64px" class="img-fluid mb-3">
|
||||
<img src="/assets/lines/<?php echo $line; ?>.svg" width="64px" class="img-fluid mb-3">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="/assets/lines/m.svg" width="64px" class="img-fluid mb-3">
|
||||
<img src="/assets/lines/<?php echo $lineId; ?>.svg" width="64px" class="img-fluid mb-3">
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$stop_name = "Champs elysées";
|
||||
include 'components/homepage/stop.php';
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
$favoriteStops = getFavorites($lineId);
|
||||
|
||||
foreach ($favoriteStops as $stop) {
|
||||
$stop_name = getStopName($stop['stopId']);
|
||||
include 'components/homepage/stop.php';
|
||||
if (count($favoriteStops) > 1) {
|
||||
echo '<hr class="mt-4">';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,72 @@
|
||||
<?php
|
||||
|
||||
$line = '2';
|
||||
include 'components/homepage/line.php';
|
||||
function getStopName($stopId) {
|
||||
$json = file_get_contents(__DIR__ . '/../../data/stops.json');
|
||||
$result = array_filter(json_decode($json, true), function($item) use ($stopId) {
|
||||
return $item['fields']['mode'] === 'METRO' && $item['fields']['id_ref_zda'] === $stopId;
|
||||
});
|
||||
|
||||
return reset($result)['fields']['nom_zda'];
|
||||
}
|
||||
|
||||
function getFavorites($lineId) {
|
||||
global $conn;
|
||||
try {
|
||||
$query = $conn->prepare("SELECT stopId FROM favorites WHERE lineId = ?");
|
||||
$query->execute([$lineId]);
|
||||
$result = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
return $result;
|
||||
} catch(PDOException $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
$query = $conn->prepare("SELECT DISTINCT lineId FROM favorites WHERE userId = ?");
|
||||
$query->execute([$_SESSION['user_id']]);
|
||||
$lineIds = $query->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
?>
|
||||
<hr>
|
||||
|
||||
<div class="px-4 my-5 text-center">
|
||||
<h1 class="display-5 fw-bold">Subway Schedule</h1>
|
||||
<div class="col-lg-6 mx-auto">
|
||||
<p class="lead mb-4">Displaying your favorite stations and lines below</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$line = '8';
|
||||
foreach ($lineIds as $lineId) {
|
||||
include 'components/homepage/line.php';
|
||||
?>
|
||||
}
|
||||
|
||||
if (empty($lineIds)) {
|
||||
echo '<div class="alert alert-info text-center" role="alert">You havent added any favorites yet.</div>';
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<script>
|
||||
function removeFavorite(stopId, lineId) {
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('stopId', stopId);
|
||||
formData.append('lineId', lineId);
|
||||
formData.append('action', 'remove');
|
||||
|
||||
fetch('/endpoints/updateFavorite.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,18 +1,56 @@
|
||||
<?php
|
||||
|
||||
$response = file_get_contents('https://prim.iledefrance-mobilites.fr/marketplace/stop-monitoring?MonitoringRef=STIF:StopArea:SP:' . $stop['stopId'] . ':',
|
||||
false, stream_context_create([
|
||||
"http" => [
|
||||
"header" => "apiKey: " . $idfm_api_key
|
||||
]
|
||||
]));
|
||||
$data = json_decode($response, true);
|
||||
|
||||
$directions = [];
|
||||
|
||||
if (isset($data['Siri']['ServiceDelivery']['StopMonitoringDelivery'][0]['MonitoredStopVisit'])) {
|
||||
foreach ($data['Siri']['ServiceDelivery']['StopMonitoringDelivery'][0]['MonitoredStopVisit'] as $visit) {
|
||||
$vehicleJourney = $visit['MonitoredVehicleJourney'];
|
||||
if (strpos($vehicleJourney['OperatorRef']['value'], '.' . $lineId . '.' . $lineId) !== false) {
|
||||
$direction = $vehicleJourney['DirectionName'][0]['value'];
|
||||
$expectedArrival = $vehicleJourney['MonitoredCall']['ExpectedArrivalTime'];
|
||||
$expectedDeparture = $vehicleJourney['MonitoredCall']['ExpectedDepartureTime'];
|
||||
|
||||
$departureTime = date('H:i', strtotime($expectedArrival . ' +2 hours'));
|
||||
|
||||
if (!isset($directions[$direction])) {
|
||||
$directions[$direction] = [];
|
||||
}
|
||||
if (count($directions[$direction]) < 2) {
|
||||
$directions[$direction][] = $departureTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$finalDirections = [];
|
||||
foreach ($directions as $direction => $times) {
|
||||
if (count($times) == 2) {
|
||||
$finalDirections[] = [
|
||||
'direction' => $direction,
|
||||
'next_departure' => $times[0],
|
||||
'following_departure' => $times[1]
|
||||
];
|
||||
} elseif (count($times) == 1) {
|
||||
$finalDirections[] = [
|
||||
'direction' => $times[0],
|
||||
'next_departure' => $times[0],
|
||||
'following_departure' => '-'
|
||||
];
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div>
|
||||
<p class="h5"><?php echo $stop_name; ?></p>
|
||||
<?php
|
||||
$directions = [
|
||||
[
|
||||
'direction' => 'Château de Vincennes',
|
||||
'next_departure' => '05:32',
|
||||
'following_departure' => '05:41'
|
||||
],
|
||||
[
|
||||
'direction' => 'Porte de Pantin',
|
||||
'next_departure' => '05:40',
|
||||
'following_departure' => '05:49'
|
||||
],
|
||||
];
|
||||
include 'stop_table.php';
|
||||
?>
|
||||
</div>
|
||||
<p class="h5 d-inline"><?php echo $stop_name; ?></p>
|
||||
<a id="remove-<?php echo $stop['stopId'] . "-" . $lineId ?>" class="btn btn-danger btn-sm mb-2" onclick="removeFavorite(<?php echo $stop['stopId'] . ',' . $lineId; ?>)"><i class="fa fa-trash"></i></a>
|
||||
</div>
|
||||
|
||||
<?php include 'stop_table.php'; ?>
|
||||
|
||||
@@ -3,18 +3,23 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Direction</th>
|
||||
<th>Prochain départ</th>
|
||||
<th>Prochain suivant</th>
|
||||
<th>Next train</th>
|
||||
<th>Following departure</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($directions as $direction): ?>
|
||||
<?php
|
||||
if (empty($finalDirections)) {
|
||||
echo '<tr><td colspan="3">This train no longer takes passengers</td></tr>';
|
||||
}
|
||||
foreach ($finalDirections as $direction):
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $direction['direction']; ?></td>
|
||||
<td><?php echo $direction['next_departure']; ?></td>
|
||||
<td><?php echo $direction['following_departure']; ?></td>
|
||||
<td><?php echo htmlspecialchars($direction['direction']); ?></td>
|
||||
<td><?php echo htmlspecialchars($direction['next_departure']); ?></td>
|
||||
<td><?php echo htmlspecialchars($direction['following_departure']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user