diff options
| author | Darkelarious <darkelarious@333networks.com> | 2017-09-25 23:13:47 +0200 |
|---|---|---|
| committer | Darkelarious <darkelarious@333networks.com> | 2017-09-25 23:13:47 +0200 |
| commit | 18921404e5454cdf202b7b4f70a2777f3e297998 (patch) | |
| tree | d24abef8f510998423cb8f107228e253ee6b4825 /lib/MasterWebInterface/Database/SQLite/Games.pm | |
| download | WebInterface-Perl-MS-Perl-18921404e5454cdf202b7b4f70a2777f3e297998.tar.gz WebInterface-Perl-MS-Perl-18921404e5454cdf202b7b4f70a2777f3e297998.zip | |
Web interface for MasterServer-Perl
Diffstat (limited to 'lib/MasterWebInterface/Database/SQLite/Games.pm')
| -rwxr-xr-x | lib/MasterWebInterface/Database/SQLite/Games.pm | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/MasterWebInterface/Database/SQLite/Games.pm b/lib/MasterWebInterface/Database/SQLite/Games.pm new file mode 100755 index 0000000..db820f6 --- /dev/null +++ b/lib/MasterWebInterface/Database/SQLite/Games.pm @@ -0,0 +1,53 @@ +package MasterWebInterface::Database::SQLite::Games; +use strict; +use warnings; +use Exporter 'import'; +our @EXPORT = qw| dbGameListGet dbGetGameDesc |; + +################################################################################ +## get list of game details +## opt: filter first letter +################################################################################ +sub dbGameListGet { + my $s = shift; + my %o = (page => 1, results => 50, sort => '', @_); + + my %where = ( + $o{firstchar} + ? ('upper(SUBSTR(description, 1, 1)) = ?' => $o{firstchar} ) : (), + $o{search} + ? ('lower(description) LIKE lower(?)' => "%$o{search}%") : (), + ); + + my @select = ( qw| description gamename num_uplink num_total |); + my $order = sprintf { + description => 'description %s', + gamename => 'gamename %s', + num_uplink => 'num_uplink %s', + num_total => 'num_total %s', + }->{ $o{sort}||'num_total' }, $o{reverse} ? 'DESC' : 'ASC'; + + my($r, $np) = $s->dbPage(\%o, q| + SELECT !s FROM games + !W + ORDER BY !s|, + join(', ', @select), \%where, $order + ); + + my $p = $s->dbAll( q| + SELECT COUNT(*) AS num + FROM games + !W|, \%where, + )->[0]{num}; + return wantarray ? ($r, $np, $p) : $r; +} + +################################################################################ +## get description for a game by gamename +################################################################################ +sub dbGetGameDesc { +my ($self, $gn) = @_; + return $self->dbAll("SELECT description FROM games WHERE gamename = ?", $gn)->[0]{description}; +} + +1; |
