diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb
index e4c03ea..0bd9ef1 100644
--- a/app/models/exported_plan.rb
+++ b/app/models/exported_plan.rb
@@ -80,9 +80,8 @@
end
def sections
- phase_id = self.phase_id ||= self.plan.template.phases.first.id # Use the first phase if none was specified
- sections = Phase.find(phase_id).sections
- sections.sort_by(&:number)
+ self.phase_id ||= self.plan.template.phases.first.id
+ Section.where({phase_id: phase_id}).order(:number)
end
def questions_for_section(section_id)
@@ -104,22 +103,25 @@
CSV.generate do |csv|
csv << [_('Section'),_('Question'),_('Answer'),_('Selected option(s)'),_('Answered by'),_('Answered at')]
self.sections.each do |section|
- self.questions_for_section(section).each do |question|
- answer = self.plan.answer(question.id)
- q_format = question.question_format
- if q_format.option_based?
- options_string = answer.question_options.collect {|o| o.text}.join('; ')
- else
- options_string = ''
+ questions = self.questions_for_section(section)
+ if questions.present?
+ questions.each do |question|
+ answer = self.plan.answer(question.id)
+ q_format = question.question_format
+ if q_format.option_based?
+ options_string = answer.question_options.collect {|o| o.text}.join('; ')
+ else
+ options_string = ''
+ end
+ csv << [
+ section.title,
+ sanitize_text(question.text),
+ question.option_comment_display ? sanitize_text(answer.text) : '',
+ options_string,
+ user.name,
+ answer.updated_at
+ ]
end
- csv << [
- section.title,
- sanitize_text(question.text),
- question.option_comment_display ? sanitize_text(answer.text) : '',
- options_string,
- user.name,
- answer.updated_at
- ]
end
end
end
@@ -128,7 +130,6 @@
def as_txt
output = "#{self.plan.title}\n\n#{self.plan.template.title}\n"
output += "\n"+_('Details')+"\n\n"
- puts 'admin_details: '+self.admin_details.inspect
self.admin_details.each do |at|
value = self.send(at)
@@ -140,34 +141,35 @@
end
self.sections.each do |section|
- output += "\n#{section.title}\n"
+ questions = self.questions_for_section(section)
+ if questions.present?
+ output += "\n#{section.title}\n"
+ questions.each do |question|
+ qtext = sanitize_text( question.text.gsub(/
/, ' * ') )
+ output += "\n* #{qtext}"
+ answer = self.plan.answer(question.id, false)
- self.questions_for_section(section).each do |question|
- qtext = sanitize_text( question.text.gsub(//, ' * ') )
- output += "\n* #{qtext}"
- answer = self.plan.answer(question.id, false)
-
- if answer.nil?
- output += _('Question not answered.')+ "\n"
- else
- q_format = question.question_format
- if q_format.option_based?
- output += answer.question_options.collect {|o| o.text}.join("\n")
- if question.option_comment_display
+ if answer.nil?
+ output += _('Question not answered.')+ "\n"
+ else
+ q_format = question.question_format
+ if q_format.option_based?
+ output += answer.question_options.collect {|o| o.text}.join("\n")
+ if question.option_comment_display
+ output += "\n#{sanitize_text(answer.text)}\n"
+ end
+ else
output += "\n#{sanitize_text(answer.text)}\n"
end
- else
- output += "\n#{sanitize_text(answer.text)}\n"
end
end
end
end
-
output
end
private
-
+ # Returns an Array of question_ids for the exported settings stored for a plan
def questions
question_settings = self.settings(:export).fields[:questions]
@questions ||= if question_settings.present?
diff --git a/app/views/plans/export.docx.erb b/app/views/plans/export.docx.erb
index 0ea56f4..7f9c2c2 100644
--- a/app/views/plans/export.docx.erb
+++ b/app/views/plans/export.docx.erb
@@ -16,30 +16,32 @@
<% @exported_plan.sections.each do |section| %>
- <%= section.title %>
- <% questions = @exported_plan.questions_for_section(section.id) %>
- <% questions.each do |question| %>
-
- <%= raw question.text %>
-
-
- <% answer = @plan.answer(question.id, false) %>
- <% if answer.nil? then %>
- <%= _('Question not answered') %>
- <% else %>
- <% q_format = question.question_format %>
- <% if q_format.option_based? %>
-
- <% answer.question_options.each do |option| %>
- - <%= raw option.text %>
- <% end %>
-
- <% if question.option_comment_display %>
- <%= raw answer.text %>
- <% end %>
- <%else%>
- <%= raw answer.text %>
- <%end%>
- <% end %>
- <% end %>
-<% end %>
+ <% questions = @exported_plan.questions_for_section(section.id)
+ if questions.present?
+ %>
+ <%= section.title %>
+ <% questions.each do |question| %>
+
+ <%= raw question.text %>
+
+ <% answer = @plan.answer(question.id, false) %>
+ <% if answer.nil? %>
+ <%= _('Question not answered') %>
+ <% else %>
+ <% q_format = question.question_format %>
+ <% if q_format.option_based? %>
+
+ <% answer.question_options.each do |option| %>
+ - <%= raw option.text %>
+ <% end %>
+
+ <% if question.option_comment_display %>
+ <%= raw answer.text %>
+ <% end %>
+ <% else %>
+ <%= raw answer.text %>
+ <% end %>
+ <% end%>
+ <% end %>
+ <% end %>
+<% end %>
diff --git a/app/views/plans/export.html.erb b/app/views/plans/export.html.erb
index 6f51388..27a6b1b 100644
--- a/app/views/plans/export.html.erb
+++ b/app/views/plans/export.html.erb
@@ -29,24 +29,25 @@
<% end %>
<% @exported_plan.sections.each do |section| %>
- <%= section.title %>
-
-
-
- | <%= _('Questions')%> |
- <%= _('Answers')%> |
-
-
-
- <% questions = @exported_plan.questions_for_section(section.id) %>
- <% questions.each do |question| %>
+ <% questions = @exported_plan.questions_for_section(section.id)
+ if questions.present? %>
+ <%= section.title %>
+
+
+
+ | <%= _('Questions')%> |
+ <%= _('Answers')%> |
+
+
+
+ <% questions.each do |question| %>
|
- <%= raw question.text %>
|
<% answer = @plan.answer(question.id, false) %>
- <% if answer.nil? then %>
+ <% if answer.nil? %>
<%= _('Question not answered') %>
<% else %>
<% q_format = question.question_format %>
@@ -56,19 +57,20 @@
<%= option.text %>
<% end %>
- <% if question.option_comment_display == true then%>
+ <% if question.option_comment_display == true %>
<%= raw answer.text %>
<% end %>
- <%else%>
+ <% else%>
<%= raw answer.text %>
- <%end%>
+ <% end%>
<% end %>
|
<% end %>
-
-
- <% end %>
+
+
+ <% end %>
+ <% end %>
diff --git a/app/views/plans/export.pdf.erb b/app/views/plans/export.pdf.erb
index 8ac7827..b9ab084 100644
--- a/app/views/plans/export.pdf.erb
+++ b/app/views/plans/export.pdf.erb
@@ -29,38 +29,39 @@
<% end %>
<% @exported_plan.sections.each do |section| %>
- <%= section.title %>
- <% questions = @exported_plan.questions_for_section(section.id) %>
- <% questions.each_with_index do |question, idx| %>
-
- <% unless idx == 0 && question.text == section.title %>
+ <% questions = @exported_plan.questions_for_section(section.id)
+ if questions.present?
+ %>
+
<%= section.title %>
+ <% questions.each do |question| %>
+
<%= raw question.text %>
- <% end %>
- <% answer = @plan.answer(question.id, false) %>
- <% if answer.nil? then %>
-
<%= _('Question not answered.') -%>
- <% else %>
- <% q_format = question.question_format %>
- <% if q_format.option_based? %>
-
- <% answer.question_options.each do |option| %>
- - <%= option.text %>
- <% end %>
-
-
- <% if question.option_comment_display == true then%>
+ <% answer = @plan.answer(question.id, false) %>
+ <% if answer.nil? then %>
+
<%= _('Question not answered.') -%>
+ <% else %>
+ <% q_format = question.question_format %>
+ <% if q_format.option_based? %>
+
+ <% answer.question_options.each do |option| %>
+ - <%= option.text %>
+ <% end %>
+
+
+ <% if question.option_comment_display == true then%>
+ <% if !answer.text.nil? then %>
+ <%= raw answer.text.gsub(/
(\s|| |<\/td>| )*(<\/tr>| |
)/,"") %>
+ <%end%>
+ <%end%>
+ <%else%>
+
<% if !answer.text.nil? then %>
<%= raw answer.text.gsub(/
(\s|| |<\/td>| )*(<\/tr>| |
)/,"") %>
<%end%>
- <%end%>
- <%else%>
-
- <% if !answer.text.nil? then %>
- <%= raw answer.text.gsub(/
(\s|| |<\/td>| )*(<\/tr>| |
)/,"") %>
- <%end%>
- <% end %>
- <% end %>
-
+ <% end %>
+ <% end %>
+
+ <% end %>
<% end %>
<% end %>