aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterWebInterface/Database/AdvancedSearch.pm
blob: a21a3c3281b33a74188cf694a62d380a3071a9ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;