Sha256: 92a895be8161c03b4e5228472534432acbe2779752fa360221b1575829b465d5

Contents?: true

Size: 1011 Bytes

Versions: 5

Compression:

Stored size: 1011 Bytes

Contents

module Classiccms
  module Routing

    #in charge of get the first item of a given model (for menu items etc.)
    def get_first_item
      Base.where(:_type => CONFIG[:model], :'connections.parrent' => nil, :'connections.section' => CONFIG[:section], :'connections.order_id'.lte => 1).first
    end

    #This method will get you the most awesome route through a tree! (OMG!)
    def get_route(current, routes = [])
      if current.kind_of? Base
        routes << current.id
        branches = Array.new
        current.connections.each_with_index do |connection, i|
          if connection.parent_id != nil and Base.where(:_id => connection.parent_id).count > 0
            branches[i] = get_route(Base.find(connection.parent_id))
          end
        end
        new = Array.new
        branches.each do |branch|
          if branch != nil and (new.count == 0 or new.count > branches.count)
            new = branch
          end
        end
        routes += new
      end
      routes
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
classiccms-0.5.11 lib/classiccms/lib/routing.rb
classiccms-0.5.10 lib/classiccms/lib/routing.rb
classiccms-0.5.9 lib/classiccms/lib/routing.rb
classiccms-0.5.8 lib/classiccms/lib/routing.rb
classiccms-0.5.7 lib/classiccms/lib/routing.rb