app/models/section.rb
#get the next loop items that should be used to render the section
# self: the section we are going to render.
# loop_item: is the node of the tree where we currently are. We need to know what are the possible branches to descend to
# loop_sources: hash that keeps record of the last item used for each loop_source in use
get the next loop items that should be used to render the section
self: the section we are going to render.
loop_item: is the node of the tree where we currently are. We need to know what are the possible branches to descend to
loop_sources: hash that keeps record of the last item used for each loop_source in use
get the next loop items that should be used to render the section self : the section we are going to render . loop_item : is the node of the tree where we currently are . We need to know what are the possible branches to descend to loop_sources : hash that keeps record of the last item used for each loop_source in use
def next_loop_items loop_item, loop_sources
    the_items = []
    if loop_item && loop_item.loop_item_type.descendants.include?(self.loop_item_type)
      the_items = loop_item.descendants.find_all_by_loop_item_type_id(self.loop_item_type_id)
    else
      if loop_sources.present? && loop_sources[self.loop_source.id.to_s] && loop_sources[self.loop_source.id.to_s].loop_item_type.descendants.include?(self.loop_item_type)
        the_items = loop_sources[self.loop_source.id.to_s].descendants.find_all_by_loop_item_type_id(self.loop_item_type_id)
      else 
        if self.loop_item_type
          the_items = self.loop_item_type.loop_items.order(:lft)
        end
      end
    end
  end
def next_loop_items loop_item , loop_sources the_items = [ ] if loop_item && loop_item . loop_item_type . descendants . include? ( self . loop_item_type ) the_items = loop_item . descendants . find_all_by_loop_item_type_id ( self . loop_item_type_id ) else if loop_sources . present? && loop_sources [ self . loop_source . id . to_s ] && loop_sources [ self . loop_source . id . to_s ] . loop_item_type . descendants . include? ( self . loop_item_type ) the_items = loop_sources [ self . loop_source . id . to_s ] . descendants . find_all_by_loop_item_type_id ( self . loop_item_type_id ) else if self . loop_item_type the_items = self . loop_item_type . loop_items . order ( :lft ) end end end end
get the next loop items that should be used to render the section
self: the section we are going to render.
get the next loop items that should be used to render the section self : the section we are going to render .
#if loop_item exists and its descendants include the self's loop_item_type, find the loop_items that correspond to that loop item type #if it's not included check what was the last loop_item of that loop_source used, that info comes inside the loop_sources hash #having the last loop_item of the loop_item loop_source get it's descendants that are of self.loop_item_type #return the section loop item type's loop_items
loop_item
loop_sources