@@ -4,9 +4,9 @@ module Api
44 module V2
55 # Helper class for the API V2 project / DMP
66 class PlanPresenter
7- attr_reader :data_contact , :contributors , :costs
7+ attr_reader :data_contact , :contributors , :costs , :complete_plan_data
88
9- def initialize ( plan :)
9+ def initialize ( plan :, complete : false )
1010 @contributors = [ ]
1111 return unless plan . present?
1212
@@ -22,6 +22,8 @@ def initialize(plan:)
2222 end
2323
2424 @costs = plan_costs ( plan : @plan )
25+
26+ @complete_plan_data = fetch_all_q_and_a if complete
2527 end
2628
2729 # Extract the ARK or DOI for the DMP OR use its URL if none exists
@@ -55,6 +57,25 @@ def plan_costs(plan:)
5557 currency_code : 'usd' , value : answer . text }
5658 end
5759 end
60+
61+ # Fetch all questions and answers from a plan, regardless of theme
62+ def fetch_all_q_and_a
63+ answers = @plan . answers
64+ return [ ] unless answers . present?
65+
66+ answers . filter_map do |answer |
67+ q = answer . question
68+ next unless q . present?
69+
70+ {
71+ id : q . id ,
72+ title : "Question #{ q . number || q . id } " ,
73+ section : q . section &.title ,
74+ question : q . text . to_s ,
75+ answer : answer . text . to_s
76+ }
77+ end
78+ end
5879 end
5980 end
6081end
0 commit comments