feat(stops) caching stops
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
<?php
|
||||
|
||||
function getStops($line) {
|
||||
$json = file_get_contents(__DIR__ . '/../../data/stops.json');
|
||||
$data = json_decode($json, true);
|
||||
$result = array_filter($data, function($item) use ($line) {
|
||||
return $item['fields']['mode'] === 'METRO' && $item['fields']['indice_lig'] === "$line";
|
||||
});
|
||||
return $result;
|
||||
function getStops($lineId) {
|
||||
global $conn;
|
||||
$stmt = $conn->prepare("SELECT * FROM stops WHERE lineId = ?");
|
||||
$stmt->execute([$lineId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function isFavorite($userId, $stopId, $lineId) {
|
||||
@@ -16,6 +14,7 @@ function isFavorite($userId, $stopId, $lineId) {
|
||||
return $stmt->rowCount() > 0;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<div class="px-4 my-5 text-center">
|
||||
@@ -29,7 +28,11 @@ function isFavorite($userId, $stopId, $lineId) {
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<?php for ($i = 1; $i <= 14; $i++): ?>
|
||||
<?php
|
||||
for ($i = 1; $i <= 14; $i++):
|
||||
$stops = getStops($i);
|
||||
if (!empty($stops)):
|
||||
?>
|
||||
<div class="col-2 mb-3">
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
@@ -44,9 +47,12 @@ function isFavorite($userId, $stopId, $lineId) {
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<?php $stations = getStops($i); ?>
|
||||
<div class="row">
|
||||
<?php include 'stop_list.php'; ?>
|
||||
<?php
|
||||
$stops = getStops($i);
|
||||
include 'stop_list.php';
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -58,7 +64,7 @@ function isFavorite($userId, $stopId, $lineId) {
|
||||
<?php if ($i % 6 === 0): ?>
|
||||
</div><div class="row">
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
<?php endif; endfor; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<div class="row">
|
||||
<?php
|
||||
$half = ceil(count($stations) / 2);
|
||||
$chunks = array_chunk($stations, $half, true);
|
||||
?>
|
||||
|
||||
<?php foreach ($chunks as $chunk): ?>
|
||||
$chunks = array_chunk($stops, ceil(count($stops) / 2), true);
|
||||
|
||||
foreach ($chunks as $chunk): ?>
|
||||
<div class="col-md-6">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
@@ -16,12 +14,12 @@
|
||||
<tbody>
|
||||
<?php foreach ($chunk as $station): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($station['fields']['nom_zda']); ?></td>
|
||||
<td><?php echo htmlspecialchars($station['name']); ?></td>
|
||||
<td class="text-end">
|
||||
<?php if (isFavorite($_SESSION['user_id'], $station['fields']['id_ref_zda'], $i)): ?>
|
||||
<button class="btn btn-danger remove-stop" data-station-id="<?= $station['fields']['id_ref_zda'] ?>" data-line-id="<?= $i ?>">Retirer</button>
|
||||
<?php if (isFavorite($_SESSION['user_id'], $station['id'], $i)): ?>
|
||||
<button class="btn btn-danger remove-stop" data-station-id="<?= $station['id'] ?>" data-line-id="<?= $i ?>">Revoke</button>
|
||||
<?php else: ?>
|
||||
<button class="btn btn-success add-stop" data-station-id="<?= $station['fields']['id_ref_zda'] ?>" data-line-id="<?= $i ?>">Ajouter</button>
|
||||
<button class="btn btn-success add-stop" data-station-id="<?= $station['id'] ?>" data-line-id="<?= $i ?>">Add</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user