new export csv table

Conflicts:

	vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb
This commit is contained in:
iCross 2013-05-23 20:56:51 +08:00
parent 15347f25dc
commit cf0d7cfc64
1 changed files with 59 additions and 46 deletions

View File

@ -89,27 +89,36 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
@survey = ::Survey.find(params[:id])
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
respond_to do |format|
format.csv do
csv = CSV.generate do |csv|
csv << @survey_questions.map(&:title)
row = []
@survey_questions.each do |question|
row << question.title
row << ' '
end
csv << row
csv_stats = []
csv_stats = @survey_questions.map do |question|
@survey_questions.each do |question|
csv_options = []
csv_counts = []
case question.type
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select, ::SurveyQuestion::Check
question.survey_question_options.map do |option|
"#{option.name} : #{(@chart_data[question.id.to_s][option.name] || 0 rescue 0)}"
csv_options << option.name
csv_counts << "#{(@chart_data[question.id.to_s][option.name] || 0 rescue 0)}"
end
when ::SurveyQuestion::Radiogroup
question.survey_question_options.map do |option|
question.survey_question_radiogroups.map do |group|
"#{option.name} - #{group.name} : #{(@chart_data[question.id.to_s][option.name][group.name] || 0 rescue 0)}"
csv_options << "#{option.name} - #{group.name}"
csv_counts << "#{(@chart_data[question.id.to_s][option.name][group.name] || 0 rescue 0)}"
end
end.flatten
else
[' ']
csv_options << " "
csv_counts << " "
end
csv_stats << csv_options
csv_stats << csv_counts
end
max_length = csv_stats.map(&:length).max
csv_stats.map do |l|
@ -129,13 +138,17 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
else
row << answer[question.id.to_s]
end
row << ' '
end
csv << row
end
end
render :text => csv
respond_to do |format|
format.csv do
response.headers["Content-Type"] = "text/csv; charset=big5"
render :text => csv.encode('Big5')
end
end
end