Class: Section

Inherits:
SectionNode show all
Defined in:
app/models/section.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SectionNode

#move_after, #move_before, #move_to, #move_to_beginning, #move_to_end, #node, #page?, #path, #public?, #root?, #section, #section=, #section?, #section_id, #section_id=, #visible?

Instance Attribute Details

#full_pathObject

Returns the value of attribute full_path.



35
36
37
# File 'app/models/section.rb', line 35

def full_path
  @full_path
end

Class Method Details

.find_by_name_path(name_path) ⇒ Object



115
116
117
118
119
120
121
122
# File 'app/models/section.rb', line 115

def self.find_by_name_path(name_path)
  section = Section.root.first
  children = name_path.split("/")[1..-1] || []
  children.each do |name|
    section = section.sections.first(:conditions => {:name => name})
  end
  section
end

.rootObject

proxys ########



163
164
165
# File 'app/models/section.rb', line 163

def self.root
  roots
end

Instance Method Details

#actual_pathObject



135
136
137
138
139
140
141
142
# File 'app/models/section.rb', line 135

def actual_path
  if root?
    "/"
  else
    p = first_page_or_link
    p ? p.path : "#"
  end
end

#all_children_with_nameObject



43
44
45
46
47
48
49
50
# File 'app/models/section.rb', line 43

def all_children_with_name
  child_sections.map do |s|
    if s.node
      s.node.full_path = root? ? s.node.name : "#{name} / #{s.node.name}"
      [s.node] << s.node.all_children_with_name
    end
  end.flatten.compact
end

#allow_groups=(code = :none) ⇒ Object

Set which groups are allowed to access this section.



153
154
155
156
157
# File 'app/models/section.rb', line 153

def allow_groups=(code=:none)
  if code == :all
    self.groups = Group.all
  end
end

#child_nodesObject



167
168
169
# File 'app/models/section.rb', line 167

def child_nodes
  children.ordered
end

#child_sectionsObject



171
172
173
# File 'app/models/section.rb', line 171

def child_sections
  sections
end

#deletable?Boolean

def empty?

  child_nodes.reject{|n| n.orphaned?}.empty?
end

Returns:

  • (Boolean)


103
104
105
# File 'app/models/section.rb', line 103

def deletable?
  !root? && empty?
end

#editable_by_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/section.rb', line 107

def editable_by_group?(group)
  group.editable_by_section(self)
end

The first page that is a decendent of this section



125
126
127
128
129
130
131
132
133
# File 'app/models/section.rb', line 125

def first_page_or_link
  section_node = child_nodes.of_type(['Link', 'Page']).first(:order => "section_nodes.position")
  return section_node.node if section_node
  sections.each do |s|
    node = s.first_page_or_link
    return node if node
  end
  nil
end

#path_not_reservedObject



144
145
146
147
148
# File 'app/models/section.rb', line 144

def path_not_reserved
  if Cms.reserved_paths.include?(path)
    errors.add(:path, "is invalid, '#{path}' a reserved path")
  end
end

#sectionsObject



174
175
176
# File 'app/models/section.rb', line 174

def sections
  children.ordered.scoped(:conditions => {:type => 'Section'})
end

#statusObject



111
112
113
# File 'app/models/section.rb', line 111

def status
  public? ? :unlocked : :locked
end

#visible_child_nodes(options = {}) ⇒ Object



37
38
39
40
41
# File 'app/models/section.rb', line 37

def visible_child_nodes(options={})
  children = child_nodes.of_type(["Section", "Page", "Link"]).all(:order => 'section_nodes.position')
  visible_children = children.select{|sn| sn.visible?}
  options[:limit] ? visible_children[0...options[:limit]] : visible_children
end