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 13fc426ca..38003893b 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 @@ -111,29 +111,29 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController question.update_attributes(title: titles[index]) end - @survey.survey_answers.destroy + @survey_answers.destroy # Modify multiline options if changed @survey_questions.each_with_index do |question, index| case question.type - when ::SurveyQuestion::Radio, ::SurveyQuestion::Select - (2..(question.survey_question_options.count + 1)).each do |row| - (1..@spreadsheet.row(row)[index*2 + 1].to_i).each do - @answer_model = @survey.survey_answers.new - @answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2] - @answer_model.save! - end - end + # when ::SurveyQuestion::Radio, ::SurveyQuestion::Select + # (2..(question.survey_question_options.count + 1)).each do |row| + # (1..@spreadsheet.row(row)[index*2 + 1].to_i).each do + # @answer_model = @survey.survey_answers.new + # @answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2] + # @answer_model.save! + # end + # end - when ::SurveyQuestion::Check - (2..(question.survey_question_options.count + 1)).each do |row| - (1..@spreadsheet.row(row)[index*2 + 1].to_i).each do - @answer_model = @survey.survey_answers.new - @answer_model[question.id.to_s] = [ @spreadsheet.row(row)[index*2] ] - @answer_model.save! - end - end + # when ::SurveyQuestion::Check + # (2..(question.survey_question_options.count + 1)).each do |row| + # (1..@spreadsheet.row(row)[index*2 + 1].to_i).each do + # @answer_model = @survey.survey_answers.new + # @answer_model[question.id.to_s] = [ @spreadsheet.row(row)[index*2] ] + # @answer_model.save! + # end + # end when ::SurveyQuestion::Radiogroup radio_groups = [] @@ -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