-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(navigate) navigation available and most usefull features)
- Loading branch information
Showing
15 changed files
with
335 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/* | ||
.idea | ||
config.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
$idfm_api_key = ''; | ||
$db_host = '127.0.0.1'; | ||
$db_name = 'subwaySchedule'; | ||
$db_user = ''; | ||
$db_password = ''; | ||
?> |
Oops, something went wrong.