diff options
| author | Darkelarious <darkelarious@333networks.com> | 2022-08-26 13:26:33 +0200 |
|---|---|---|
| committer | Darkelarious <darkelarious@333networks.com> | 2022-08-26 13:26:33 +0200 |
| commit | 8ec88b566c5f3edc65f25adc0716c3493689cd08 (patch) | |
| tree | dbbde9a694f6b4052ec39a45f0010955c668da3c /lib/MasterWebInterface/Database/AdvancedSearch.pm | |
| parent | c5f43733533fe9b5708bd065a12c5fac86ccebed (diff) | |
| download | WebInterface-Perl-8ec88b566c5f3edc65f25adc0716c3493689cd08.tar.gz WebInterface-Perl-8ec88b566c5f3edc65f25adc0716c3493689cd08.zip | |
advanced filtering
Diffstat (limited to 'lib/MasterWebInterface/Database/AdvancedSearch.pm')
| -rwxr-xr-x | lib/MasterWebInterface/Database/AdvancedSearch.pm | 51 |
1 files changed, 51 insertions, 0 deletions
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; |
