Class: SpudMenuItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SpudMenuItem
- Defined in:
- app/models/spud_menu_item.rb
Class Method Summary collapse
- .grouped(menu) ⇒ Object
-
.options_tree_for_item(menu, config = {}) ⇒ Object
Returns an array of pages in order of heirarchy :fitler Filters out a page by ID, and all of its children :value Pick an attribute to be used in the value field, defaults to ID.
Instance Method Summary collapse
Class Method Details
.grouped(menu) ⇒ Object
35 36 37 |
# File 'app/models/spud_menu_item.rb', line 35 def self.grouped() return ..group_by(&:parent_type) end |
.options_tree_for_item(menu, config = {}) ⇒ Object
Returns an array of pages in order of heirarchy :fitler Filters out a page by ID, and all of its children
:value Pick an attribute to be used in the value field, defaults to ID
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/spud_menu_item.rb', line 42 def self.(,config={}) collection = config[:collection] || self.grouped() level = config[:level] || 0 parent_id = config[:parent_id] || nil parent_type = config[:parent_type] || 'SpudMenu' filter = config[:filter] || nil value = config[:value] || :id list = [] if parent_type == 'SpudMenu' && collection[parent_type] item_collection = collection['SpudMenuItem'].group_by(&:parent_id) if collection['SpudMenuItem'] collection[parent_type].each do |c| if filter.blank? || c.id != filter.id list << [level.times.collect{ '- ' }.join('') + c.name, c[value]] list += self.(,{:collection => item_collection, :parent_id => c.id, :level => level+1, :filter => filter,:parent_type => "SpudMenuItem"}) end end else if collection[parent_id] collection[parent_id].each do |c| if filter.blank? || c.id != filter.id list << [level.times.collect{ '- ' }.join('') + c.name, c[value]] list += self.(,{:collection => collection, :parent_id => c.id, :level => level+1, :filter => filter,:parent_type => "SpudMenuItem"}) end end end end return list end |
Instance Method Details
#get_url ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/models/spud_menu_item.rb', line 15 def get_url if !self.spud_page.blank? return self.spud_page.url_name else return url end end |
#options_tree(options, depth, current = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/spud_menu_item.rb', line 23 def (,depth,current = nil) sub_items = self. sub_items = sub_items.where(["id != ?",current.id]) if !current.blank? && !current.id.blank? if(sub_items.blank?) return end sub_items.each do |item| << ["#{'-'*depth} #{item.name}",item.id] = item.(,depth+1,current) end return end |