Class: CategoryType

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/category_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.category_mapObject

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



12
13
14
15
16
17
# File 'app/models/category_type.rb', line 12

def self.category_map
  all.inject(Hash.new([])) do |map, ct| 
    map[ct.id.to_s] = ct.category_list.map{|c| [c.path, c.id.to_s]}
    map
  end
end

.display_nameObject



34
35
36
# File 'app/models/category_type.rb', line 34

def self.display_name
  I18n.t("models.category_type.display_name")
end

.display_name_pluralObject



38
39
40
# File 'app/models/category_type.rb', line 38

def self.display_name_plural
   I18n.t("models.category_type.display_name_plural")
end

Instance Method Details

#cannot_be_deleted_messageObject



30
31
32
# File 'app/models/category_type.rb', line 30

def cannot_be_deleted_message
  categories.count.zero? ? nil : I18n.t("models.category_type.cannot_be_deleted", :count => categories.count)
end

#category_list(order = "name") ⇒ Object

This is used to get the full list of categories for this category type in the correct order.



20
21
22
23
24
25
26
27
28
# File 'app/models/category_type.rb', line 20

def category_list(order="name")
  list = []
  fn = lambda do |cat|
    list << cat
    cat.children.all(:order => order).each{|c| fn.call(c)}
  end
  categories.top_level.all(:order => order).each{|cat| fn.call(cat)}
  list
end