diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index c284b2c7a..9884121f6 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -705,7 +705,7 @@ class PollController < ApplicationController sheet1[count_row + 1,0] = l(:label_poll_subtotal) sheet1[count_row + 2,0] = l(:label_poll_proportion) poll_question.poll_answers.each_with_index do |poll_answer,i| - sheet1[count_row, i + 1] = poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") + sheet1[count_row, i + 1] = poll_answer.answer_text == "" ? l(:label_poll_other) : poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") sheet1[count_row + 1, i + 1] = poll_answer.poll_votes.count sheet1[count_row + 2, i + 1] = statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)).to_s + "%" end @@ -717,27 +717,58 @@ class PollController < ApplicationController sheet1[count_row,0] = l(:label_poll_question_num,:num => poll_question.question_number) sheet1[count_row,1] = poll_question.question_title count_row += 1 - poll_question.poll_votes.each do |poll_vote| - sheet1[count_row,0] = poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") + if poll_question.question_type == 3 + poll_question.poll_votes.each do |poll_vote| + sheet1[count_row,0] = poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") + count_row += 1 + end count_row += 1 + else + count = 0 + poll_question.poll_answers.reorder("answer_position asc").each_with_index do |poll_answer,i| + sheet1.row(count_row).default_format = blue + sheet1[count_row, i] = poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") + count = poll_question.poll_votes.where("poll_answer_id = #{poll_answer.id}").count > count ? poll_question.poll_votes.where("poll_answer_id = #{poll_answer.id}").count : count + poll_question.poll_votes.where("poll_answer_id = #{poll_answer.id}").each_with_index do |poll_vote, j| + sheet1[count_row + j + 1,i] = poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") + end + end + count_row = count_row + count + 2 end - count_row += 1 end end sheet1.row(count_row).default_format = blue sheet1[count_row ,0] = l(:label_bidding_user_studentname) - poll_questions.each_with_index do |poll_question, i| - sheet1[count_row ,i + 1] = poll_question.question_title + current_index = 1 + poll_questions.each do |poll_question| + if poll_question.question_type == 4 + poll_question.poll_answers.reorder("answer_position asc").each do |ans| + sheet1[count_row ,current_index] = poll_question.question_title + "(#{ans.answer_text})" + current_index += 1 + end + else + sheet1[count_row ,current_index] = poll_question.question_title + current_index += 1 + end end count_row += 1 @poll.users.each do |user| sheet1[count_row ,0] = user.show_name + current_index = 1 poll_questions.each_with_index do |poll_question, i| if poll_question.question_type == 1 || poll_question.question_type == 2 - sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") if poll_vote.poll_answer}.join(";") + sheet1[count_row ,current_index] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.poll_answer.answer_text.gsub(/<\/?.*?>/,"").gsub(/ /," ") if poll_vote.poll_answer}.join(";") + current_index += 1 + elsif poll_question.question_type == 3 + sheet1[count_row ,current_index] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/ /," ")}.join(";") + current_index += 1 else - sheet1[count_row ,i + 1] = user.poll_votes.where(:poll_question_id => poll_question.id).map{|poll_vote| poll_vote.vote_text.gsub(/<\/?.*?>/,"").gsub(/ /," ")}.join(";") + poll_question.poll_answers.reorder("answer_position asc").each do |ans| + poll_vote = user.poll_votes.where(:poll_question_id => poll_question.id, :poll_answer_id => ans.id).first + sheet1[count_row ,current_index] = poll_vote.nil? ? "" : poll_vote.vote_text + current_index += 1 + end end end count_row += 1 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index d57f29c39..6a6ffad44 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2019,6 +2019,7 @@ zh: label_poll_title: 问卷标题 label_poll_description: 问卷描述 label_poll_options: 选项 + label_poll_other: 其他 label_poll_subtotal: 小计 label_poll_question_num: "第%{num}题" label_poll_proportion: 比例