Sha256: 0d0afb81246b0f69f1dd1333b18c83b4b6e4f6020764197e222f47f61305d296

Contents?: true

Size: 1.06 KB

Versions: 21

Compression:

Stored size: 1.06 KB

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]).each do |item|
        if item.connections.where(:parent_id => nil, :section => CONFIG[:section], :order_id.lte => 1).count > 0
          return item
        end
      end
      return nil
    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

21 entries across 21 versions & 1 rubygems

Version Path
classiccms-0.7.5 lib/classiccms/lib/routing.rb
classiccms-0.7.4 lib/classiccms/lib/routing.rb
classiccms-0.7.3 lib/classiccms/lib/routing.rb
classiccms-0.7.2 lib/classiccms/lib/routing.rb
classiccms-0.7.1 lib/classiccms/lib/routing.rb
classiccms-0.7.0 lib/classiccms/lib/routing.rb
classiccms-0.6.9 lib/classiccms/lib/routing.rb
classiccms-0.6.8 lib/classiccms/lib/routing.rb
classiccms-0.6.7 lib/classiccms/lib/routing.rb
classiccms-0.6.6 lib/classiccms/lib/routing.rb
classiccms-0.6.5 lib/classiccms/lib/routing.rb
classiccms-0.6.4 lib/classiccms/lib/routing.rb
classiccms-0.6.3 lib/classiccms/lib/routing.rb
classiccms-0.6.2 lib/classiccms/lib/routing.rb
classiccms-0.6.1 lib/classiccms/lib/routing.rb
classiccms-0.6.0 lib/classiccms/lib/routing.rb
classiccms-0.5.17 lib/classiccms/lib/routing.rb
classiccms-0.5.16 lib/classiccms/lib/routing.rb
classiccms-0.5.15 lib/classiccms/lib/routing.rb
classiccms-0.5.14 lib/classiccms/lib/routing.rb