diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 5684072..368f077 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -86,7 +86,7 @@ end def questions_for_section(section_id) - questions.where(section_id: section_id).sort_by(&:number) + Question.where(id: questions).where(section_id: section_id).order(:number) end def admin_details @@ -128,6 +128,8 @@ value = self.send(at) if value.present? output += admin_field_t(at.to_s) + ": " + value + "\n" + else + output += admin_field_t(at.to_s) + ": " + _('-') + "\n" end end @@ -162,18 +164,17 @@ private def questions - @questions ||= begin - question_settings = self.settings(:export).fields[:questions] - - return [] if question_settings.is_a?(Array) && question_settings.empty? - - questions = if question_settings.present? && question_settings != :all - Question.where(id: question_settings) + question_settings = self.settings(:export).fields[:questions] + @questions ||= if question_settings.present? + if question_settings == :all + Question.where(section_id: self.plan.sections.collect { |s| s.id }).pluck(:id) + elsif question_settings.is_a?(Array) + question_settings else - Question.where(section_id: self.plan.sections.collect {|s| s.id }) + [] end - - questions.order(:number) + else + [] end end diff --git a/app/views/plans/export.html.erb b/app/views/plans/export.html.erb index 990af6c..8e79cc4 100644 --- a/app/views/plans/export.html.erb +++ b/app/views/plans/export.html.erb @@ -22,7 +22,7 @@ %>

- <%= admin_field_t(field.to_s) -%>

- <%= value.present? ? value : _('-') -%> + <%= value.present? ? value : _('-') %> <% end %> diff --git a/app/views/plans/export.pdf.erb b/app/views/plans/export.pdf.erb index c41b244..874acd4 100644 --- a/app/views/plans/export.pdf.erb +++ b/app/views/plans/export.pdf.erb @@ -21,9 +21,10 @@

<%= @plan.title %>

<% @exported_plan.admin_details.each do |field| value = @exported_plan.send(field) - if value.present? - %> -

<%= admin_field_t(field.to_s) -%> <%= value -%>

+ if value.present? %> +

<%= admin_field_t(field.to_s) -%> <%= value -%>

+ <% else %> +

<%= admin_field_t(field.to_s) -%> <%= _('-') %>

<% end %> <% end %>