forked from catarse/catarse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Reports | ||
module Users | ||
autoload :Backers, 'reports/users/backers' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#encoding:utf-8 | ||
module Reports | ||
module Users | ||
class Backers | ||
class << self | ||
def most_backed(limit=20) | ||
@users = User.joins(:backs).select( | ||
<<-SQL | ||
users.id, | ||
users.name, | ||
count(backers.id) as count_backs | ||
SQL | ||
).order("count_backs desc").group("users.name, users.id").limit(limit) | ||
|
||
@csv = CSV.generate(:col_sep => ',') do |csv_string| | ||
|
||
# TODO: Change this later *order and names to use i18n* | ||
# for moment header only in portuguese. | ||
csv_string << [ | ||
'ID', | ||
'Nome do apoiador', | ||
'Total de apoios' | ||
] | ||
|
||
@users.each do |user| | ||
csv_string << [ | ||
user.id, | ||
user.display_name, | ||
user.count_backs | ||
] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |