Commit 74c709c76bf5dd17a91a252bfd84df01768486df
1 parent
45c506ba
Exists in
master
and in
1 other branch
Changes to support multiple datetime graphs
Showing
1 changed file
with
18 additions
and
4 deletions
Show diff stats
app/controllers/questions_controller.rb
... | ... | @@ -116,17 +116,31 @@ class QuestionsController < InheritedResources::Base |
116 | 116 | def object_info_totals_by_date |
117 | 117 | authenticate |
118 | 118 | |
119 | - # eventually allow for users to specify type of export through params[:type] | |
119 | + object_type = params[:object_type] | |
120 | + | |
120 | 121 | @question = current_user.questions.find(params[:id]) |
121 | - hash = Vote.count(:conditions => "question_id = #{@question.id}", :group => "date(created_at)") | |
122 | + if object_type == 'votes' | |
123 | + # eventually allow for users to specify type of export through params[:type] | |
124 | + hash = Vote.count(:conditions => "question_id = #{@question.id}", :group => "date(created_at)") | |
125 | + elsif object_type == 'user_submitted_ideas' | |
126 | + hash = Choice.count(:include => 'item', | |
127 | + :conditions => "choices.question_id = #{@question.id} AND items.creator_id <> #{@question.creator_id}", | |
128 | + :group => "date(choices.created_at)") | |
129 | + elsif object_type == 'user_sessions' | |
130 | + # little more work to do here: | |
131 | + result = Vote.find(:all, :select => 'date(created_at) as date, voter_id, count(*) as vote_count', | |
132 | + :conditions => "question_id = #{@question.id}", :group => 'date(created_at), voter_id') | |
133 | + hash = Hash.new(0) | |
134 | + result.each do |r| | |
135 | + hash[r.date]+=1 | |
136 | + end | |
137 | + end | |
122 | 138 | |
123 | 139 | respond_to do |format| |
124 | 140 | format.xml { render :xml => hash.to_xml and return} |
125 | 141 | end |
126 | 142 | end |
127 | 143 | |
128 | - | |
129 | - | |
130 | 144 | protected |
131 | 145 | def export_votes |
132 | 146 | @question = Question.find(params[:id]) | ... | ... |