Class | CategoryType |
In: |
app/models/category_type.rb
|
Parent: | ActiveRecord::Base |
Return a map when the key is category type id as a string and the value is an array of arrays, each entry having the first value as the category path and the second value being the category id as a string
# File app/models/category_type.rb, line 12 12: def self.category_map 13: all.inject(Hash.new([])) do |map, ct| 14: map[ct.id.to_s] = ct.category_list.map{|c| [c.path, c.id.to_s]} 15: map 16: end 17: end
# File app/models/category_type.rb, line 30 30: def cannot_be_deleted_message 31: categories.count.zero? ? nil : "This cannot be deleted because it is in use in #{categories.count} #{"category".pluralize(categories.count)}" 32: end
This is used to get the full list of categories for this category type in the correct order.
# File app/models/category_type.rb, line 20 20: def category_list(order="name") 21: list = [] 22: fn = lambda do |cat| 23: list << cat 24: cat.children.all(:order => order).each{|c| fn.call(c)} 25: end 26: categories.top_level.all(:order => order).each{|cat| fn.call(cat)} 27: list 28: end