From 7177303eeb4899010db5af9c831b85504813970b Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 16 Jan 2015 15:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E7=BB=9F=E8=AE=A1=E6=9C=80?= =?UTF-8?q?=E7=BB=88=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 2 +- app/helpers/poll_helper.rb | 18 ++++++++- app/views/poll/_choice_show.html.erb | 49 ++++++++++++----------- app/views/poll/statistics_result.html.erb | 10 ++--- config/locales/zh.yml | 5 +++ 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 3de4e8339..3b4bf3694 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -86,7 +86,7 @@ class PollController < ApplicationController def statistics_result @poll = Poll.find(params[:id]) poll_questions = @poll.poll_questions - @poll_questions = paginateHelper poll_questions,3 #分页 + @poll_questions = paginateHelper poll_questions, 5 respond_to do |format| format.html{render :layout => 'base_courses'} end diff --git a/app/helpers/poll_helper.rb b/app/helpers/poll_helper.rb index 7816d8e37..1a8fabae3 100644 --- a/app/helpers/poll_helper.rb +++ b/app/helpers/poll_helper.rb @@ -27,7 +27,7 @@ module PollHelper false end end - + #获取文本题答案 def get_anwser_vote_text(question_id,user_id) pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id) @@ -47,4 +47,20 @@ module PollHelper true end end + + #统计答题百分比 + def statistics_result_percentage(e, t) + return e*100/t + end + + def options_show p + case p + when 1 + "单选题" + when 2 + "多选题" + else + "问答题" + end + end end \ No newline at end of file diff --git a/app/views/poll/_choice_show.html.erb b/app/views/poll/_choice_show.html.erb index aa425e748..16971d5ad 100644 --- a/app/views/poll/_choice_show.html.erb +++ b/app/views/poll/_choice_show.html.erb @@ -1,25 +1,28 @@ -
- - - - - - - - <% poll_question.poll_answers.each do |poll_answer| %> - - - - - - <% end %> - - - - - - -
选项 小计 比例
<%= poll_answer.answer_text %> <% poll_answer.poll_votes.count %>
75%
本题有效填写人次 <%= poll_question.poll_votes.count %> 
-
+ + + + + + + + <% poll_question.poll_answers.each do |poll_answer| %> + + + + + + <% end %> + + + + + + +
<%= l(:label_poll_options) %> <%= l(:label_poll_subtotal) %> <%= l(:label_poll_proportion) %>
<%= poll_answer.answer_text %> <%= poll_answer.poll_votes.count %> +
+ +
+ <%= statistics_result_percentage(poll_answer.poll_votes.count, @poll.users.count) %>%
<%= l(:label_poll_valid_commit) %> <%= poll_question.poll_votes.count %> 
+ diff --git a/app/views/poll/statistics_result.html.erb b/app/views/poll/statistics_result.html.erb index d6181fb1a..dea18f8d8 100644 --- a/app/views/poll/statistics_result.html.erb +++ b/app/views/poll/statistics_result.html.erb @@ -2,14 +2,14 @@ - 问卷调查_问卷结果 + <%= l(:label_poll_result) %> <%= stylesheet_link_tag 'polls', :media => 'all' %>
-

某问卷统计

+

<%= @poll.polls_name %> <%= l(:label_poll) %>

<% @poll_questions.each do |poll_question| %> @@ -17,7 +17,8 @@
  1. - 第<%= poll_question.question_number %>题:<%= poll_question.question_title %> [单选题]<% poll_question.poll_answers %> + 第<%= poll_question.question_number %>题:<%= poll_question.question_title %> + [<%= options_show(poll_question.question_type) %>]
    <%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %>
  2. @@ -28,11 +29,8 @@
    - -
    -
    答题已完成 0%
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 95ab07d5d..5c2925b90 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2253,5 +2253,10 @@ zh: label_new_answer: 新建选项 label_poll_title: 问卷标题 label_poll_description: 问卷描述 + label_poll_options: 选项 + label_poll_subtotal: 小计 + label_poll_proportion: 比例 + label_poll_valid_commit: 本题有效填写人次 + label_poll_result: 问卷调查_问卷统计