Class: Category
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Category
show all
- Defined in:
- app/models/category.rb
Instance Method Summary
collapse
Instance Method Details
#category_picture ⇒ Object
27
28
29
30
31
32
33
|
# File 'app/models/category.rb', line 27
def category_picture
unless self.attachments.empty?
self.attachments.first.public_filename(:categories_icon)
else
'folder'
end
end
|
#descendants ⇒ Object
45
46
47
|
# File 'app/models/category.rb', line 45
def descendants
(children + children.map(&:descendants)).flatten
end
|
#kind ⇒ Object
15
16
17
|
# File 'app/models/category.rb', line 15
def kind
read_attribute(:type)
end
|
#kind=(kind) ⇒ Object
19
20
21
|
# File 'app/models/category.rb', line 19
def kind=(kind)
write_attribute(:type, kind)
end
|
#level ⇒ Object
11
12
13
|
# File 'app/models/category.rb', line 11
def level
return self.ancestors.length
end
|
#to_jstree ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'app/models/category.rb', line 35
def to_jstree
hash = {}
hash[:attr] = { :id => "#{self.class.to_s.underscore}_#{id}", :type => 'folder' }
hash[:data] = { :title => name, :icon => category_picture, :attr => { :title => total_elements_count } }
unless children.empty?
hash[:children] = children.all(:order => 'position ASC').collect(&:to_jstree)
end
hash
end
|
#total_elements_count ⇒ Object
23
24
25
|
# File 'app/models/category.rb', line 23
def total_elements_count
([elements.count('id')] + children.all(:select => 'id,type').map(&:total_elements_count)).sum
end
|