diff --git a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb index 88d642456..d3c5fa87d 100644 --- a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb @@ -145,6 +145,28 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController radio_groups << @spreadsheet.row(line)[index * 2] end + # Grab answers info + answers = [] + (spreadsheet_radiogroups_lines..@spreadsheet.last_row).each do |line| + + if not @spreadsheet.row(line)[index * 2].blank? + answers << eval(@spreadsheet.row(line)[index * 2]) + end + end + + # Save the answers + answers.each do |answer| + options = Hash[question.survey_question_options.collect { |o| [ o.id.to_s, o.name ] }] + @answer_model = @survey.survey_answers.new + @answer_model[question.id.to_s] = {} + + answer.each do |option, value| + @answer_model[question.id.to_s][options.invert[option]] = value + end + + @answer_model.save! + end + # Parse the needed info in the array radio_titles = [] radio_options = [] @@ -179,7 +201,6 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController question.survey_question_radiogroups.each_with_index do |option, index| groups_of_radios.each do |radios| if radios[index] != option.name_translations["zh_tw"] - binding.pry option.update_attributes(name: radios[index]) break end