[Bps-public-commit] App-Changeloggr branch, master, updated. fa9bdfeaabab0c28228e48d1c517388772773e21

Alex M Vandiver alexmv at bestpractical.com
Wed May 27 18:02:09 EDT 2009


The branch, master has been updated
       via  fa9bdfeaabab0c28228e48d1c517388772773e21 (commit)
      from  71217e8a994ee69f222db68a204265c9fa53ecca (commit)

Summary of changes:
 lib/App/Changeloggr/Model/User.pm |   14 ++++++++++++++
 lib/App/Changeloggr/View.pm       |   11 ++---------
 2 files changed, 16 insertions(+), 9 deletions(-)

- Log -----------------------------------------------------------------
commit fa9bdfeaabab0c28228e48d1c517388772773e21
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Wed May 27 18:02:05 2009 -0400

    Get your SQL out of my view class!

diff --git a/lib/App/Changeloggr/Model/User.pm b/lib/App/Changeloggr/Model/User.pm
index a5c29b8..afdc63e 100644
--- a/lib/App/Changeloggr/Model/User.pm
+++ b/lib/App/Changeloggr/Model/User.pm
@@ -69,5 +69,19 @@ sub votes {
     return M('VoteCollection', user_id => $self->id);
 }
 
+sub vote_placement {
+    my $self = shift;
+    my $votes = $self->votes->count;
+    my $place = Jifty->handle->simple_query(<<"EOSQL")->fetch->[0];
+select count(*)
+  from (select user_id
+          from votes
+         group by votes.user_id
+        having count(*) >= $votes);
+EOSQL
+    $place++ unless $votes;
+    return ($votes, $place);
+}
+
 1;
 
diff --git a/lib/App/Changeloggr/View.pm b/lib/App/Changeloggr/View.pm
index 628b61a..f7a20c9 100644
--- a/lib/App/Changeloggr/View.pm
+++ b/lib/App/Changeloggr/View.pm
@@ -82,15 +82,8 @@ template '/vote-on-change' => sub {
 template '/score' => sub {
     div {
         {id is "score"};
-        my $votes = Jifty->web->current_user->user_object->votes->count;
-        my $place = Jifty->handle->simple_query(<<"EOSQL")->fetch->[0];
-select count(*)
-  from (select user_id
-          from votes
-         group by votes.user_id
-        having count(*) >= $votes);
-EOSQL
-        $place++ unless $votes;
+        my $user = Jifty->web->current_user->user_object;
+        my($votes, $place) = $user->vote_placement;
         outs _("You have %quant(%1,vote), and are currently ranked #%2!", $votes, $place);
     };
 };

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list