From 5156701094cf5e0bc7cb796d383fb71bb28574bc Mon Sep 17 00:00:00 2001 From: thomaschen <99703040@nccu.edu.tw> Date: Mon, 21 Oct 2013 17:37:34 +0800 Subject: [PATCH] import 'check' and 'select' question success --- .../survey/back_end/surveys_controller.rb | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 b68805f62..ec8123c46 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 @@ -101,7 +101,7 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController else raise "Unknown file type: #{file.original_filename}" end - @current_row = 2 + @start_row = 2 @header = @spreadsheet.row(1) # (2..@spreadsheet.last_row).each do |i| @@ -109,17 +109,24 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController # end @survey.survey_answers.destroy - @survey_questions.each_with_index do |question,column| + @survey_questions.each_with_index do |question,index| case question.type when ::SurveyQuestion::Radio, ::SurveyQuestion::Select - (@current_row..(@current_row + question.survey_question_options.count - 1)).each do |row| - (1..@spreadsheet.row(row)[column + 1].to_i).each do + (@start_row..(@start_row + 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)[column] + @answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2] @answer_model.save! end - end - @current_row = @current_row + question.survey_question_options.count - 1 + end + when ::SurveyQuestion::Check + (@start_row..(@start_row + 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 else end end