app/models/section.rb
# Set section and descendants sections' Submission state to care (dont_care = false). To be considered in the root submission state.
# The method will go through the section descendants using the looping_identifier, if it exists, but stops using it if it comes across a looping section, as the
# looping_identifier would be different. If the method finds a section that is dependent it will break, as there's no way to know if that section is available or not.
#
# @param [User] user
# @param [String] looping_identifier looping_identifier relative to the section the state is being updated
Set section and descendants sections' Submission state to care (dont_care = false). To be considered in the root submission state.
The method will go through the section descendants using the looping_identifier, if it exists, but stops using it if it comes across a looping section, as the
looping_identifier would be different. If the method finds a section that is dependent it will break, as there's no way to know if that section is available or not.
Set section and descendants sections ' Submission state to care ( dont_care = false ) . To be considered in the root submission state . The method will go through the section descendants using the looping_identifier if it exists but stops using it if it comes across a looping section as the looping_identifier would be different . If the method finds a section that is dependent it will break as there ' s no way to know if that section is available or not .
def update_submission_state_to_care user, looping_identifier=nil
    if (dependent = self.dependent_descendants)
      to_update = self.self_and_descendants - dependent.map{ |d| d.self_and_descendants }.flatten
    else
      to_update = self.self_and_descendants
    end
    l_descendants = self.looping_descendants
    if !l_descendants.empty?
      if looping_identifier.present?
        all_l_descendants = l_descendants.map{ |s| s.self_and_descendants }.flatten
        to_update = to_update - all_l_descendants
        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}%'")
        UserSectionSubmissionState.update_all({:dont_care => false}, {:section_id => to_update.map{ |s| s.id }, :user_id => user.id, :looping_identifier => looping_identifier})
      else
        UserSectionSubmissionState.update_all({:dont_care => false}, {:section_id => to_update.map{ |s| s.id }, :user_id => user.id})
      end
    else
      UserSectionSubmissionState.update_all({:dont_care => false}, {:section_id => to_update.map{ |s| s.id }, :user_id => user.id, :looping_identifier => looping_identifier})
    end
  end
def update_submission_state_to_care user , looping_identifier = nil if ( dependent = self . dependent_descendants ) to_update = self . self_and_descendants - dependent . map { | d | d . self_and_descendants } . flatten else to_update = self . self_and_descendants end l_descendants = self . looping_descendants if ! l_descendants . empty? if looping_identifier . present? all_l_descendants = l_descendants . map { | s | s . self_and_descendants } . flatten to_update = to_update - all_l_descendants 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}%'" ) UserSectionSubmissionState . update_all ( { :dont_care => false } , { :section_id => to_update . map { | s | s . id } , :user_id => user . id , :looping_identifier => looping_identifier } ) else UserSectionSubmissionState . update_all ( { :dont_care => false } , { :section_id => to_update . map { | s | s . id } , :user_id => user . id } ) end else UserSectionSubmissionState . update_all ( { :dont_care => false } , { :section_id => to_update . map { | s | s . id } , :user_id => user . id , :looping_identifier => looping_identifier } ) end end
Set section and descendants sections' Submission state to care (dont_care = false).
Set section and descendants sections ' Submission state to care ( dont_care = false ) .
#UserSectionSubmissionState.update_all({:dont_care => false}, {:section_id => self.id, :user_id => user.id, :looping_identifier => looping_identifier})
user
looping_identifier
looping_identifier looping_identifier relative to the section the state is being updated
looping_identifier looping_identifier relative to the section the state is being updated