summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-10-27 19:19:47 +0100
committerYorhel <git@yorhel.nl>2008-10-27 19:19:47 +0100
commitf266cd214111a1c71f705edbc9243d8625693003 (patch)
treec9ba1eb4de5b3b6f2f5b369b5b5a0c2917a62755
parent0c5411d6da14c641efc9ae8f0e50ca047f6c8c22 (diff)
Database statistics are now fetched from the DB
...and I created yet another *::Misc module...
-rw-r--r--lib/VNDB/DB/Misc.pm27
-rw-r--r--lib/VNDB/Util/CommonHTML.pm24
2 files changed, 42 insertions, 9 deletions
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
new file mode 100644
index 00000000..50a12a4b
--- /dev/null
+++ b/lib/VNDB/DB/Misc.pm
@@ -0,0 +1,27 @@
+
+package VNDB::DB::Misc;
+
+use strict;
+use warnings;
+use Exporter 'import';
+
+our @EXPORT = qw|
+ dbStats
+|;
+
+
+# Arguments: array of elements to get stats from, options:
+# vn, producers, releases, users, threads, posts
+# Returns: hashref, key = element, value = number of entries
+sub dbStats {
+ my $s = shift;
+ return { map {
+ $_ => $s->dbRow('SELECT COUNT(*) as cnt FROM !s !W',
+ /posts/ ? 'threads_posts' : $_,
+ /producers|vn|releases|threads|posts/ ? { 'hidden = ?' => 0 } : {}
+ )->{cnt} - (/users/ ? 1 : 0);
+ } @_ };
+}
+
+1;
+
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index 1b1d9225..153112f1 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -36,6 +36,8 @@ sub htmlHeader { # %options->{ title }
sub _menu {
+ my $self = shift;
+
div id => 'menulist';
div class => 'menubox';
@@ -57,19 +59,23 @@ sub _menu {
# show user or login menubox here
- # these stats are fake, need to be fetched from the DB
+ my @stats = (
+ [ vn => 'Visual Novels' ],
+ [ releases => 'Releases' ],
+ [ producers => 'Producers' ],
+ [ users => 'Users' ],
+ [ threads => 'Threads' ],
+ [ posts => 'Posts' ],
+ );
+ my $stats = $self->dbStats(map $$_[0], @stats);
div class => 'menubox';
h2 'Database Statistics';
div;
dl;
- dt 'Visual Novels';
- dd 1232;
- dt 'Releases';
- dd 3940;
- dt 'Producers';
- dd 643;
- dt 'Users';
- dd 769;
+ for (@stats) {
+ dt $$_[1];
+ dd $stats->{$$_[0]};
+ }
end;
br style => 'clear: left';
end;