2014-10-06 05:55:25 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
wb = xlsx_package.workbook
|
2016-04-18 10:48:59 +00:00
|
|
|
wb.add_worksheet(name: @survey.title[0..15]) do |sheet|
|
2014-10-06 05:55:25 +00:00
|
|
|
|
|
|
|
row = []
|
|
|
|
@survey_questions.each_with_index do |question, i|
|
|
|
|
if question.type == 2 or question.type == 3 or question.type == 4
|
|
|
|
question.survey_question_options.each do |option|
|
|
|
|
row << "#{i+1}. #{question.title} - #{option.name}"
|
|
|
|
end
|
|
|
|
elsif question.type == 5
|
|
|
|
question.survey_question_options.each do |option|
|
|
|
|
question.survey_question_radiogroups.each do |radiogroup|
|
|
|
|
row << "#{i+1}. #{question.title} - #{option.name} - #{radiogroup.name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
row << "#{i+1}. #{question.title}"
|
|
|
|
end
|
|
|
|
if question.custom_option
|
|
|
|
row << "#{i+1}. #{question.title} - #{t('survey_question.use_custom_option')}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sheet.add_row row
|
|
|
|
|
|
|
|
@survey_answers.each do |answer|
|
|
|
|
answer_row = []
|
|
|
|
@survey_questions.each do |question|
|
|
|
|
|
|
|
|
options = question.survey_question_options.collect{|o| o.name }
|
|
|
|
|
|
|
|
if question.type == 2 or question.type == 4
|
|
|
|
|
|
|
|
options.collect do |o|
|
|
|
|
|
|
|
|
if !answer[question.id.to_s].blank? && answer[question.id.to_s].include?(o)
|
|
|
|
answer_row << '1'
|
|
|
|
else
|
|
|
|
answer_row << ''
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif question.type == 3
|
|
|
|
|
|
|
|
options.collect do |o|
|
|
|
|
|
|
|
|
if !answer[question.id.to_s].blank? && answer[question.id.to_s].include?(o)
|
|
|
|
answer_row << '1'
|
|
|
|
else
|
|
|
|
answer_row << ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elsif question.type == 5
|
|
|
|
|
|
|
|
question.survey_question_options.each do |option|
|
|
|
|
question.survey_question_radiogroups.each do |radiogroup|
|
|
|
|
if !answer[question.id.to_s].blank? && answer[question.id.to_s][option.id.to_s] == radiogroup.name
|
|
|
|
answer_row << '1'
|
|
|
|
else
|
|
|
|
answer_row << ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
if answer[question.id.to_s]
|
|
|
|
answer_row << answer[question.id.to_s]
|
|
|
|
else
|
|
|
|
answer_row << ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if question.custom_option
|
|
|
|
if !answer[question.id.to_s].blank?
|
|
|
|
if answer[question.id.to_s].class == Array
|
|
|
|
answer_row << (answer[question.id.to_s] - options).join
|
|
|
|
elsif answer[question.id.to_s].class == String
|
|
|
|
answer_row << ([answer[question.id.to_s]] - options).join
|
|
|
|
end
|
|
|
|
else
|
|
|
|
answer_row << ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sheet.add_row answer_row
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|