diff --git a/app/models/plan.rb b/app/models/plan.rb index 436a851..186c2c6 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -952,87 +952,6 @@ private - # reconnect the various parts of the hash so that: - # plan = { - # template: - # phases: - # sections: - # questions: - # answers - # } - # - # becomes a nested structure like so - # - # plan = { template: { - # phases: [ { - # sections: [ { - # questions: [ { - # answers: [...] - # - def fixup_hash(plan) - # sort out guidance first so we can add it to the questions - # before rolling up - # - ghash = {} - plan["guidance_groups"].map{|g| ghash[g["id"]] = g} - plan["plan_guidance_groups"].each do |pgg| - pgg["guidance_group"] = ghash[ pgg["guidance_group_id"] ] - end - - rollup(plan, "notes", "answer_id", "answers") - rollup(plan, "answers", "question_id", "questions") - rollup(plan, "questions", "section_id", "sections", true) - rollup(plan, "sections", "phase_id", "phases", true) - - plan["template"]["phases"] = plan.delete("phases") - plan["template"]["phases"].sort! { |x,y| x["number"].to_i <=> y["number"].to_i } - - plan["template"]["org"] = Org.find(plan["template"]["org_id"]).serializable_hash() - - # when editing phases we want the number of questions answered - # so calculate that now - plan["template"]["phases"].each do |phase| - phase["sections"].each do |section| - nanswers = 0 - section["questions"].each do |question| - if question.has_key?("answers") && question["answers"].first["text"].present? - nanswers += 1 - end - end - section["nanswers"] = nanswers - end - end - end - - - # find all object under src_plan_key - # merge them into the items under obj_plan_key using - # super_id = id - # so we have answers which each have a question_id - # rollup(plan, "answers", "quesiton_id", "questions") - # will put the answers into the right questions. - # sort determines whether the items being rolled up should be sorted by number field - def rollup(plan, src_plan_key, super_id, obj_plan_key, sort = false) - id_to_obj = Hash.new() - plan[src_plan_key].each do |o| - id = o[super_id] - if !id_to_obj.has_key?(id) - id_to_obj[id] = Array.new - end - id_to_obj[id] << o - end - - plan[obj_plan_key].each do |o| - id = o["id"] - if id_to_obj.has_key?(id) - if sort - id_to_obj[ id ].sort! { |x,y| x["number"].to_i <=> y["number"].to_i } - end - o[src_plan_key] = id_to_obj[ id ] - end - end - plan.delete(src_plan_key) - end ## # adds a user to the project