From 08878eab8102993ed84fab8b57a39a569a332809 Mon Sep 17 00:00:00 2001 From: Per Qvarforth Date: Sat, 26 Feb 2022 13:11:11 +0000 Subject: [PATCH] station search using ogn registration --- .../repositories/stationrepository.class.php | 22 +++++++++++-------- htdocs/public/views/latest.php | 2 +- htdocs/public/views/search.php | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/htdocs/includes/repositories/stationrepository.class.php b/htdocs/includes/repositories/stationrepository.class.php index 9a23bf7..315aac2 100644 --- a/htdocs/includes/repositories/stationrepository.class.php +++ b/htdocs/includes/repositories/stationrepository.class.php @@ -197,20 +197,24 @@ class StationRepository extends ModelRepository } $pdo = PDOConnection::getInstance(); - $stmt = $pdo->prepare( - 'select * from station - where latest_confirmed_packet_timestamp is not null - and latest_confirmed_packet_timestamp > ? - and (source_id != 5 or latest_confirmed_packet_timestamp > ?) - and name ilike ? + $stmt = $pdo->prepare(' + select s.* + from station s + left outer join ogn_device d on d.device_id = s.latest_ogn_sender_address + where s.latest_confirmed_packet_timestamp is not null + and s.latest_confirmed_packet_timestamp > ? + and (s.source_id != 5 or s.latest_confirmed_packet_timestamp > ?) + and (s.name ilike ? or d.registration ilike ? or d.cn ilike ?) order by name limit ? offset ?' ); $stmt->bindValue(1, (time() - $activeDuringLatestNumberOfSeconds)); $stmt->bindValue(2, (time() - (60*60*24))); // OGN data should be deleted after 24h, but just to be safe we avoid including older data when searching - $stmt->bindValue(3, "$q%"); - $stmt->bindValue(4, $limit); - $stmt->bindValue(5, $offset); + $stmt->bindValue(3, "$q%"); + $stmt->bindValue(4, "$q%"); + $stmt->bindValue(5, "$q%"); + $stmt->bindValue(6, $limit); + $stmt->bindValue(7, $offset); $stmt->execute(); $records = $stmt->fetchAll(PDO::FETCH_ASSOC); diff --git a/htdocs/public/views/latest.php b/htdocs/public/views/latest.php index 3a23887..178a47a 100644 --- a/htdocs/public/views/latest.php +++ b/htdocs/public/views/latest.php @@ -56,7 +56,7 @@ sourceId == 5 && $foundStation->getOgnDevice() !== null) : ?> -
Registration:
getOgnDevice()->registration); ?>
+
Registration:
getOgnDevice()->registration); ?> getOgnDevice()->cn ? '[' .htmlspecialchars($foundStation->getOgnDevice()->cn) . ']' : ''; ?>
Aircraft Model:
getOgnDevice()->aircraftModel); ?> getObjectById($foundStation->latestPacketId, $foundStation->latestPacketTimestamp); ?> diff --git a/htdocs/public/views/search.php b/htdocs/public/views/search.php index 0b92dbe..be20674 100644 --- a/htdocs/public/views/search.php +++ b/htdocs/public/views/search.php @@ -78,7 +78,7 @@ sourceId == 5 && $foundStation->getOgnDevice() !== null) : ?> -
Registration:
getOgnDevice()->registration); ?>
+
Registration:
getOgnDevice()->registration); ?> getOgnDevice()->cn ? '[' .htmlspecialchars($foundStation->getOgnDevice()->cn) . ']' : ''; ?>
Aircraft Model:
getOgnDevice()->aircraftModel); ?> getObjectById($foundStation->latestPacketId, $foundStation->latestPacketTimestamp); ?>