diff --git a/.gitignore b/.gitignore index 4438f37..722ad88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/* .idea +config.php diff --git a/components/homepage/line.php b/components/homepage/line.php index c31825c..a8ce6a9 100644 --- a/components/homepage/line.php +++ b/components/homepage/line.php @@ -1,9 +1,20 @@ -
- - +
+
+
+    + +
- -
\ No newline at end of file + 1) { + echo '
'; + } + } + ?> +
+
diff --git a/components/homepage/main.php b/components/homepage/main.php index b71d25b..4a8350a 100644 --- a/components/homepage/main.php +++ b/components/homepage/main.php @@ -1,10 +1,72 @@ 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); + ?> -
+ +
+

Subway Schedule

+
+

Displaying your favorite stations and lines below

+ +
+
+ \ No newline at end of file +} + +if (empty($lineIds)) { + echo ''; +} +?> + + + diff --git a/components/homepage/stop.php b/components/homepage/stop.php index d0bd5e6..08e7157 100644 --- a/components/homepage/stop.php +++ b/components/homepage/stop.php @@ -1,18 +1,56 @@ + [ + "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' => '-' + ]; + } +} +?> +
-

- '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'; - ?> -
\ No newline at end of file +

+ " class="btn btn-danger btn-sm mb-2" onclick="removeFavorite()"> + + + diff --git a/components/homepage/stop_table.php b/components/homepage/stop_table.php index f063082..c535cac 100644 --- a/components/homepage/stop_table.php +++ b/components/homepage/stop_table.php @@ -3,18 +3,23 @@ Direction - Prochain départ - Prochain suivant + Next train + Following departure - + This train no longer takes passengers'; + } + foreach ($finalDirections as $direction): + ?> - - - + + + - \ No newline at end of file + diff --git a/components/navigate/main.php b/components/navigate/main.php index 8dfb17e..74a8adf 100644 --- a/components/navigate/main.php +++ b/components/navigate/main.php @@ -7,36 +7,98 @@ function getStops($line) { return $item['fields']['mode'] === 'METRO' && $item['fields']['indice_lig'] === "$line"; }); return $result; -} +} + +function isFavorite($userId, $stopId, $lineId) { + global $conn; + $stmt = $conn->prepare("SELECT * FROM favorites WHERE userId = ? AND stopId = ? AND lineId = ?"); + $stmt->execute([$userId, $stopId, $lineId]); + return $stmt->rowCount() > 0; +} ?> -

Lignes de Métro

-
- -
-
-
- - Logo Ligne <?= $i ?> - -