Commit fa19002c151bf435e9b8d888581ec4dc74207ebc
1 parent
fff49b47
Exists in
master
and in
1 other branch
Add tracking of user submitted ideas
Showing
2 changed files
with
28 additions
and
0 deletions
Show diff stats
app/controllers/questions_controller.rb
@@ -25,6 +25,33 @@ class QuestionsController < InheritedResources::Base | @@ -25,6 +25,33 @@ class QuestionsController < InheritedResources::Base | ||
25 | end | 25 | end |
26 | end | 26 | end |
27 | 27 | ||
28 | + def object_info_totals_by_question_id | ||
29 | + total_ideas_by_q_id = Choice.count(:include => ['item', 'question'], | ||
30 | + :conditions => "items.creator_id <> questions.creator_id", | ||
31 | + :group => "choices.question_id") | ||
32 | + | ||
33 | + active_ideas_by_q_id = Choice.count(:include => ['item', 'question'], | ||
34 | + :conditions => "choices.active = 1 AND items.creator_id <> questions.creator_id", | ||
35 | + :group => "choices.question_id") | ||
36 | + | ||
37 | + combined_hash = {} | ||
38 | + | ||
39 | + total_ideas_by_q_id.each do |q_id, num_total| | ||
40 | + combined_hash[q_id] = {} | ||
41 | + combined_hash[q_id][:total_ideas] = num_total | ||
42 | + if(active_ideas_by_q_id.has_key?(q_id)) | ||
43 | + combined_hash[q_id][:active_ideas]= active_ideas_by_q_id[q_id] | ||
44 | + else | ||
45 | + combined_hash[q_id][:active_ideas]= 0 | ||
46 | + end | ||
47 | + end | ||
48 | + respond_to do |format| | ||
49 | + format.xml { render :xml => combined_hash.to_xml and return} | ||
50 | + end | ||
51 | + | ||
52 | + end | ||
53 | + | ||
54 | + | ||
28 | 55 | ||
29 | def show | 56 | def show |
30 | @question = Question.find(params[:id]) | 57 | @question = Question.find(params[:id]) |
config/routes.rb
@@ -9,6 +9,7 @@ ActionController::Routing::Routes.draw do |map| | @@ -9,6 +9,7 @@ ActionController::Routing::Routes.draw do |map| | ||
9 | :suspend => :put}, | 9 | :suspend => :put}, |
10 | :collection => {:all_num_votes_by_visitor_id => :get, | 10 | :collection => {:all_num_votes_by_visitor_id => :get, |
11 | :all_object_info_totals_by_date => :get, | 11 | :all_object_info_totals_by_date => :get, |
12 | + :object_info_totals_by_question_id => :get, | ||
12 | :recent_votes_by_question_id => :get} do |question| | 13 | :recent_votes_by_question_id => :get} do |question| |
13 | question.resources :items | 14 | question.resources :items |
14 | question.resources :prompts, :member => {:vote_left => :post, :vote_right => :post, :skip => :post, :vote => :post}, | 15 | question.resources :prompts, :member => {:vote_left => :post, :vote_right => :post, :skip => :post, :vote => :post}, |