From 8ec88b566c5f3edc65f25adc0716c3493689cd08 Mon Sep 17 00:00:00 2001 From: Darkelarious Date: Fri, 26 Aug 2022 13:26:33 +0200 Subject: advanced filtering --- lib/MasterWebInterface/Database/AdvancedSearch.pm | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 lib/MasterWebInterface/Database/AdvancedSearch.pm (limited to 'lib/MasterWebInterface/Database/AdvancedSearch.pm') diff --git a/lib/MasterWebInterface/Database/AdvancedSearch.pm b/lib/MasterWebInterface/Database/AdvancedSearch.pm new file mode 100755 index 0000000..a21a3c3 --- /dev/null +++ b/lib/MasterWebInterface/Database/AdvancedSearch.pm @@ -0,0 +1,51 @@ +package MasterWebInterface::Database::AdvancedSearch; +use strict; +use warnings; +use Exporter 'import'; +our @EXPORT = qw| dbGetGameTypes dbGetCountries |; + +sub dbGetGameTypes +{ + my $s = shift; + my %o = ( @_ ); + + my %where = ( + # gamename and char are "all" or value + $o{gamename} ? ('serverlist.gamename = ?' => $o{gamename}) : (), + ('gametype IS NOT NULL' => ""), + + # do not filter by country. the gametype can still exist for that game while there are no online servers for it. + #$o{country} ? ('country LIKE UPPER(?)' => $o{country}) : (), + ); + + return $s->dbAll( q| + SELECT DISTINCT gametype FROM serverlist + LEFT JOIN serverinfo ON serverlist.id = serverinfo.sid + !W ORDER BY lower(gametype) ASC|, + \%where, + ); +} + +sub dbGetCountries +{ + my $s = shift; + my %o = ( @_ ); + + my %where = ( + $o{gamename} ? ('serverlist.gamename = ?' => $o{gamename}) : (), + $o{hostname} ? ('LOWER(hostname) LIKE LOWER(?)' => "%$o{hostname}%") : (), + $o{mapname} ? ('(LOWER(mapname) LIKE LOWER(?) OR LOWER(maptitle) LIKE LOWER(?))' => ["%$o{mapname}%", "%$o{mapname}%"]) : (), + $o{gametype} ? ('LOWER(gametype) LIKE LOWER(?)' => $o{gametype}) : (), + + ("COUNTRY IS NOT NULL" => ""), + ); + + return $s->dbAll( q| + SELECT DISTINCT country FROM serverlist + LEFT JOIN serverinfo ON serverlist.id = serverinfo.sid + !W ORDER BY lower(country) ASC|, + \%where, + ); +} + +1; -- cgit v1.2.3