Commit cc084f198a33d2fb5c55cf9cf37f703b8a9656f8
1 parent
d8562559
Exists in
master
and in
1 other branch
Export visitor ids by question creator
Showing
1 changed file
with
22 additions
and
7 deletions
Show diff stats
app/controllers/questions_controller.rb
@@ -213,13 +213,28 @@ class QuestionsController < InheritedResources::Base | @@ -213,13 +213,28 @@ class QuestionsController < InheritedResources::Base | ||
213 | end | 213 | end |
214 | 214 | ||
215 | def all_num_votes_by_visitor_id | 215 | def all_num_votes_by_visitor_id |
216 | - votes_by_visitor_id= Vote.all(:select => 'visitors.identifier as thevi, count(*) as the_votes_count', | ||
217 | - :joins => :voter, | ||
218 | - :group => "voter_id") | ||
219 | - visitor_id_hash = {} | ||
220 | - votes_by_visitor_id.each do |visitor| | ||
221 | - visitor_id_hash[visitor.thevi] = visitor.the_votes_count | ||
222 | - visitor_id_hash[visitor.thevi] = visitor.the_votes_count | 216 | + scope = params[:scope] |
217 | + | ||
218 | + if scope == "all_votes" | ||
219 | + | ||
220 | + votes_by_visitor_id= Vote.all(:select => 'visitors.identifier as thevi, count(*) as the_votes_count', | ||
221 | + :joins => :voter, | ||
222 | + :group => "voter_id") | ||
223 | + visitor_id_hash = {} | ||
224 | + votes_by_visitor_id.each do |visitor| | ||
225 | + visitor_id_hash[visitor.thevi] = visitor.the_votes_count | ||
226 | + visitor_id_hash[visitor.thevi] = visitor.the_votes_count | ||
227 | + end | ||
228 | + elsif scope == "creators" | ||
229 | + | ||
230 | + questions_created_by_visitor_id = Question.all(:select => 'visitors.identifier as thevi, count(*) as questions_count', | ||
231 | + :joins => :creator, | ||
232 | + :group => 'creator_id') | ||
233 | + visitor_id_hash = {} | ||
234 | + questions_created_by_visitor_id.each do |visitor| | ||
235 | + visitor_id_hash[visitor.thevi] = visitor.questions_count | ||
236 | + end | ||
237 | + | ||
223 | end | 238 | end |
224 | respond_to do |format| | 239 | respond_to do |format| |
225 | format.xml{ render :xml => visitor_id_hash.to_xml and return} | 240 | format.xml{ render :xml => visitor_id_hash.to_xml and return} |