aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterWebInterface/Database/Games.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2021-09-05 20:35:44 +0200
committerDarkelarious <darkelarious@333networks.com>2021-09-05 20:35:44 +0200
commit3470e2605595bf52b3ba07bf0b3886e5a61d3e06 (patch)
tree36e7fcf008183b464aca47b7eeba0953dd36feef /lib/MasterWebInterface/Database/Games.pm
downloadWebInterface-Perl-3470e2605595bf52b3ba07bf0b3886e5a61d3e06.tar.gz
WebInterface-Perl-3470e2605595bf52b3ba07bf0b3886e5a61d3e06.zip
first version of masterinterface
Diffstat (limited to 'lib/MasterWebInterface/Database/Games.pm')
-rwxr-xr-xlib/MasterWebInterface/Database/Games.pm61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/MasterWebInterface/Database/Games.pm b/lib/MasterWebInterface/Database/Games.pm
new file mode 100755
index 0000000..02b6ad9
--- /dev/null
+++ b/lib/MasterWebInterface/Database/Games.pm
@@ -0,0 +1,61 @@
+package MasterWebInterface::Database::Games;
+use strict;
+use warnings;
+use Exporter 'import';
+our @EXPORT = qw| dbGameListGet dbGetGameDesc |;
+
+# Get list of games
+sub dbGameListGet
+{
+ my $s = shift;
+ my %o = (
+ page => 1,
+ results => 50,
+ sort => '',
+ @_
+ );
+
+ # search criteria
+ my %where = (
+ $o{search} ? ('lower(label) LIKE lower(?)' => "%$o{search}%") : (),
+ !$o{all} ? ( 'num_total > ?' => 0) : (),
+ );
+
+ # what to get from db
+ my @select = (
+ qw| label gamename num_direct num_total |
+ );
+
+ # sort order
+ my $order = sprintf {
+ label => 'label %s',
+ gamename => 'gamename %s',
+ num_total => 'num_total %s',
+ }->{ $o{sort}||'num_total' }, $o{reverse} ? 'DESC' : 'ASC';
+
+ # query
+ my($r, $np) = $s->dbPage(
+ \%o,
+ q| SELECT !s FROM gameinfo !W ORDER BY !s|,
+ join(', ', @select),
+ \%where,
+ $order
+ );
+
+ # page numbering
+ my $p = $s->dbAll(
+ q| SELECT COUNT(*) AS num FROM gameinfo !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 label FROM gameinfo WHERE gamename = ?", $gn)->[0]{label};
+}
+
+1;