diff --git a/lib/gamification_plugin/dashboard_helper.rb b/lib/gamification_plugin/dashboard_helper.rb index 22a9801..a17586a 100644 --- a/lib/gamification_plugin/dashboard_helper.rb +++ b/lib/gamification_plugin/dashboard_helper.rb @@ -15,4 +15,14 @@ module GamificationPlugin::DashboardHelper HashWithIndifferentAccess.new(Merit::PointRules::AVAILABLE_RULES)[point.score.category][:description] end + def ranking(from_date=nil, limit=10) + # FIXME move these queries to profile model + ranking = Profile.select('profiles.*, sum(num_points) as gamification_points, ROW_NUMBER() OVER(order by sum(num_points) DESC) as gamification_position').joins(:sash => {:scores => :score_points}).where(:type => 'Person').order('sum(num_points) DESC').group('profiles.id') + ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present? + current_person_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => current_person.id).first + ranking = ranking.limit(limit) + + render :partial => 'gamification/ranking', :locals => {:ranking => ranking, :current_person_ranking => current_person_ranking} + end + end diff --git a/views/gamification/_ranking.html.erb b/views/gamification/_ranking.html.erb new file mode 100644 index 0000000..f2c2a58 --- /dev/null +++ b/views/gamification/_ranking.html.erb @@ -0,0 +1,21 @@ +