Commit b22222a8bb9432e958b980c3d1b6728888cb48d4

Authored by Victor Costa
1 parent 3bd7c4a3

Be prepared for rails4

lib/ext/environment.rb
... ... @@ -6,7 +6,7 @@ class Environment
6 6 has_many :gamification_plugin_organization_badges, :through => :organizations
7 7  
8 8 def gamification_plugin_badges
9   - GamificationPlugin::Badge.from("#{gamification_plugin_organization_badges.union(gamification_plugin_environment_badges).to_sql} as #{GamificationPlugin::Badge.table_name}")
  9 + GamificationPlugin::Badge.joins('inner join profiles on profiles.id = owner_id').where(['owner_id = ? or profiles.environment_id = ?', self.id, self.id])
10 10 end
11 11  
12 12 end
... ...
lib/gamification_plugin/badge.rb
1   -class GamificationPlugin::Badge < Noosfero::Plugin::ActiveRecord
  1 +class GamificationPlugin::Badge < ActiveRecord::Base
2 2  
3 3 belongs_to :owner, :polymorphic => true
4 4  
... ...
lib/gamification_plugin/dashboard_helper.rb
... ... @@ -27,7 +27,7 @@ module GamificationPlugin::DashboardHelper
27 27  
28 28 def ranking(target, from_date=nil, limit=10)
29 29 # FIXME move these queries to profile model
30   - 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 => target.class).order('sum(num_points) DESC').group('profiles.id')
  30 + 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 => target.class).reorder('sum(num_points) DESC').group('profiles.id')
31 31 ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present?
32 32 target_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => target.id).first
33 33  
... ...
views/gamification/_ranking.html.erb
1   -<% if ranking.empty? %>
  1 +<% if ranking.blank? %>
2 2 <div class="ranking-empty"><%= _('Not enough points for this ranking yet') %></div>
3 3 <% else %>
4 4 <ul class="ranking <%= defined?(ranking_class) ? ranking_class : '' %>">
... ...