diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2017-09-21 16:06:33 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2017-09-21 16:06:33 +0200 |
commit | 0615ed0ff77ba49a919edf9274a8933872f6f403 (patch) | |
tree | aedf10a5594d4fcde8b08b8cc6b6b01b633d8c19 | |
parent | f056292472cfc9d4e8dc63d6f9fc10d32ebe0ae1 (diff) | |
download | sourceyard-0615ed0ff77ba49a919edf9274a8933872f6f403.tar.gz sourceyard-0615ed0ff77ba49a919edf9274a8933872f6f403.tar.bz2 |
Implement statistics framework
-rw-r--r-- | lib/Sourceyard/Controller.pm | 10 | ||||
-rw-r--r-- | lib/Sourceyard/Controller/Main.pm | 4 | ||||
-rw-r--r-- | lib/Sourceyard/Statistics.pm | 31 | ||||
-rw-r--r-- | templates/layouts/default.html.ep | 12 |
4 files changed, 53 insertions, 4 deletions
diff --git a/lib/Sourceyard/Controller.pm b/lib/Sourceyard/Controller.pm index 58fd4b7..e7cdd2f 100644 --- a/lib/Sourceyard/Controller.pm +++ b/lib/Sourceyard/Controller.pm @@ -29,8 +29,6 @@ sub set_user { if ($user) { $self->stash(user => $user); - use Data::Dumper; - print Dumper([$user]); $theme = ucfirst($user->theme); } @@ -39,8 +37,14 @@ sub set_user { $theme = $self->config->get(qw(default theme)); } - print "SETTING THEME $theme\n"; $self->stash(theme => $theme); } +use Sourceyard::Statistics; + +sub statistics { + my $self = shift; + return $self->{_sy_stat} ||= new Sourceyard::Statistics($self); +} + 1; diff --git a/lib/Sourceyard/Controller/Main.pm b/lib/Sourceyard/Controller/Main.pm index e3d2f36..64f2565 100644 --- a/lib/Sourceyard/Controller/Main.pm +++ b/lib/Sourceyard/Controller/Main.pm @@ -6,7 +6,9 @@ sub index { my $self = shift; $self->render(msg => 'Welcome', - is_logged_in => $self->session('logged_in')); + statistics => $self->statistics, + is_logged_in => $self->session('logged_in'), + ); } sub login { diff --git a/lib/Sourceyard/Statistics.pm b/lib/Sourceyard/Statistics.pm new file mode 100644 index 0000000..e60fe63 --- /dev/null +++ b/lib/Sourceyard/Statistics.pm @@ -0,0 +1,31 @@ +package Sourceyard::Statistics; + +use strict; +use warnings; + +use parent 'Exporter'; + +sub new { + my ($class, $ctl) = @_; + return bless { _db => $ctl->db }, $class; +} + +sub db { + my ($self) = @_; + return $self->{_db}; +} + +sub users { + my ($self, $status) = @_; + $status ||= 'A'; + unless ($self->{_users}{$status}) { + $self->{_users}{$status} = + $self->db->resultset('User') + ->search({ status => $status }) + ->count; + } + return $self->{_users}{$status}; +} + + +1; diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index cb38ee3..110db3a 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -17,11 +17,23 @@ <div class="main"><a name="top"></a> <div class="indexright"> +% if (my $stat = stash 'statistics') { <div class="box"> <div class="boxtitle"> <a href="/stats/" class="sortbutton">Statistics</a> </div><!-- boxtitle --> + <div class="boxitem"> + <span class="smaller"> + <strong><%= $stat->users %></strong> registered users + </span> + </div> +%# <div class="boxitemalt"> +%# <span class="smaller"> +%# <strong><%= $stat->projects %></strong> hosted projects +%# </span> +%# </div> </div> <!-- box --> +% } </div> <!-- indexright --> <div class="indexcenter"> |