app/models/section.rb
# This method goes through a section and its descendants questions and removes the existing answers.
# It then sets those sections submission state to dont_care, so that they are overlooked by the Root Section when calculating the Root Section Submission state
#
# @param [User] user
# @param [Intenger] looping_identifier associated with the section being saved
This method goes through a section and its descendants questions and removes the existing answers.
It then sets those sections submission state to dont_care, so that they are overlooked by the Root Section when calculating the Root Section Submission state
This method goes through a section and its descendants questions and removes the existing answers . It then sets those sections submission state to dont_care so that they are overlooked by the Root Section when calculating the Root Section Submission state
def destroy_related_answers!(user, looping_identifier=nil)
    with_current_l_identifier = self.self_and_descendants
    looping = self.looping_descendants
    if !looping.empty?
      if looping_identifier.present?
        all_l_descendants = looping.map{ |s| s.self_and_descendants }.flatten
        with_current_l_identifier = with_current_l_identifier - all_l_descendants
        Answer.destroy_all("question_id IN (#{all_l_descendants.map{ |s| s.questions.map{ |q| q.id } }.flatten.join(',')}) AND user_id = #{user.id} AND looping_identifier iLIKE '#{looping_identifier}#{LoopItem::LOOPING_ID_SEPARATOR}%'")
        UserSectionSubmissionState.update_all({:dont_care => false}, "section_id IN (#{all_l_descendants.map{ |s| s.id }.join(',')}) AND user_id = #{user.id} AND looping_identifier iLIKE '#{looping_identifier}#{LoopItem::LOOPING_ID_SEPARATOR}%'")
        Answer.destroy_all({:question_id => with_current_l_identifier.map{ |s| s.questions.map{ |q| q.id } }.flatten, :user_id => user.id, :looping_identifier => looping_identifier})
        UserSectionSubmissionState.update_all({:dont_care => true}, {:section_id => with_current_l_identifier.map{ |s| s.id }, :user_id => user.id, :looping_identifier => looping_identifier})
      else
        Answer.destroy_all({:question_id => with_current_l_identifier.map{ |s| s.questions.map{ |q| q.id } }.flatten, :user_id => user.id})
        UserSectionSubmissionState.update_all({:dont_care => true}, {:section_id => with_current_l_identifier.map{ |s| s.id }, :user_id => user.id})
      end
    else
      Answer.destroy_all({:question_id => with_current_l_identifier.map{ |s| s.questions.map{ |q| q.id } }.flatten, :user_id => user.id, :looping_identifier => looping_identifier})
      UserSectionSubmissionState.update_all({:dont_care => true}, {:section_id => with_current_l_identifier.map{ |s| s.id }, :user_id => user.id, :looping_identifier => looping_identifier})
    end
  end
def destroy_related_answers! ( user , looping_identifier = nil ) with_current_l_identifier = self . self_and_descendants looping = self . looping_descendants if ! looping . empty? if looping_identifier . present? all_l_descendants = looping . map { | s | s . self_and_descendants } . flatten with_current_l_identifier = with_current_l_identifier - all_l_descendants Answer . destroy_all ( "question_id IN (#{all_l_descendants.map{ |s| s.questions.map{ |q| q.id } }.flatten.join(',')}) AND user_id = #{user.id} AND looping_identifier iLIKE '#{looping_identifier}#{LoopItem::LOOPING_ID_SEPARATOR}%'" ) UserSectionSubmissionState . update_all ( { :dont_care => false } , "section_id IN (#{all_l_descendants.map{ |s| s.id }.join(',')}) AND user_id = #{user.id} AND looping_identifier iLIKE '#{looping_identifier}#{LoopItem::LOOPING_ID_SEPARATOR}%'" ) Answer . destroy_all ( { :question_id => with_current_l_identifier . map { | s | s . questions . map { | q | q . id } } . flatten , :user_id => user . id , :looping_identifier => looping_identifier } ) UserSectionSubmissionState . update_all ( { :dont_care => true } , { :section_id => with_current_l_identifier . map { | s | s . id } , :user_id => user . id , :looping_identifier => looping_identifier } ) else Answer . destroy_all ( { :question_id => with_current_l_identifier . map { | s | s . questions . map { | q | q . id } } . flatten , :user_id => user . id } ) UserSectionSubmissionState . update_all ( { :dont_care => true } , { :section_id => with_current_l_identifier . map { | s | s . id } , :user_id => user . id } ) end else Answer . destroy_all ( { :question_id => with_current_l_identifier . map { | s | s . questions . map { | q | q . id } } . flatten , :user_id => user . id , :looping_identifier => looping_identifier } ) UserSectionSubmissionState . update_all ( { :dont_care => true } , { :section_id => with_current_l_identifier . map { | s | s . id } , :user_id => user . id , :looping_identifier => looping_identifier } ) end end
This method goes through a section and its descendants questions and removes the existing answers.
This method goes through a section and its descendants questions and removes the existing answers .
user
looping_identifier
looping_identifier associated with the section being saved
looping_identifier associated with the section being saved