diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 9f9163d..de50db4 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -38,7 +38,7 @@ # # get the ids of the dynamically selected guidance groups # and keep a map of them so we can extract the names later - guidance_groups_ids = @plan.plan_guidance_groups.select{|pgg| pgg.selected}.map{|pgg| pgg.guidance_group.id} + guidance_groups_ids = @plan.plan_guidance_groups.map{|pgg| pgg.guidance_group.id} guidance_groups = GuidanceGroup.includes({guidances: :themes}).find(guidance_groups_ids) # create a map from theme to array of guidances diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 971f08e..e0f6648 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -108,7 +108,7 @@ @plan.assign_creator(current_user.id) @all_guidance_groups = @plan.get_guidance_group_options - @selected_guidance_groups = @plan.plan_guidance_groups.pluck(:guidance_group_id) + @selected_guidance_groups = @plan.guidance_groups.pluck(:id) respond_to do |format| if @plan.save diff --git a/app/models/plan.rb b/app/models/plan.rb index 5b284b0..6718a3b 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -153,16 +153,27 @@ # # @return Array def get_guidance_group_options - ggroups = GuidanceGroup.all - # funder organisations - # default guidance (dcc) - # own organisation? + # find all the themes in this plan + # and get the guidance groups they belong to + ggroups = [] + self.template.phases.each do |phase| + phase.sections.each do |section| + section.questions.each do |question| + question.themes.each do |theme| + theme.guidances.each do |guidance| + ggroups << guidance.guidance_group + end + end + end + end + end + return ggroups.uniq! end - ## + ## # returns the guidances associated with the project's organisation, for a specified question # # @param question [Question] the question to find guidance for @@ -197,7 +208,7 @@ end # Get guidance by theme from any guidance groups currently selected - self.plan_guidance_groups.where(selected: true).each do |pgg| + self.plan_guidance_groups.each do |pgg| group = pgg.guidance_group group.guidances.each do |guidance| common_themes = guidance.themes.all & question.themes.all @@ -210,6 +221,9 @@ return guidances end + + + ## # adds the given guidance to a hash indexed by a passed guidance group and theme #