Class: Cms::SectionNode

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

Instance Method Summary collapse

Instance Method Details

#ancestry_pathObject



106
107
108
# File 'app/models/cms/section_node.rb', line 106

def ancestry_path
  path_ids.join "/"
end

#move_after(section_node) ⇒ Object



88
89
90
91
92
93
94
95
# File 'app/models/cms/section_node.rb', line 88

def move_after(section_node)
  if section == section_node.section && position < section_node.position
    pos = section_node.position
  else
    pos = section_node.position + 1
  end
  move_to(section_node.section, pos)
end

#move_before(section_node) ⇒ Object



79
80
81
82
83
84
85
86
# File 'app/models/cms/section_node.rb', line 79

def move_before(section_node)
  if section == section_node.section && position < section_node.position
    pos = section_node.position - 1
  else
    pos = section_node.position
  end
  move_to(section_node.section, pos)
end

#move_to(section, position) ⇒ Object

Parameters:

  • section (Section)
  • position (Integer)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/cms/section_node.rb', line 57

def move_to(section, position)
  #logger.info "Moving Section Node ##{id} to Section ##{sec.id} Position #{pos}"
  transaction do
    if self.parent != section.node
      remove_from_list
      self.parent = section.node
      save
    end
    if position < 0
      position = 0
    else
      #This helps prevent the position from getting out of whack
      #If you pass in a really high number for position, 
      #this just corrects it to the right number
      node_count =Cms::SectionNode.count(:conditions => {:ancestry => ancestry})
      position = node_count if position > node_count
    end
    
    insert_at_position(position)
  end
end

#move_to_beginning(sec) ⇒ Object



97
98
99
# File 'app/models/cms/section_node.rb', line 97

def move_to_beginning(sec)
  move_to(sec, 0)
end

#move_to_end(sec) ⇒ Object



101
102
103
104
# File 'app/models/cms/section_node.rb', line 101

def move_to_end(sec)
  #1.0/0 == Infinity
  move_to(sec, 1.0/0)
end

#orphaned?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/cms/section_node.rb', line 41

def orphaned?
  !node || (node.class.uses_soft_delete? && node.deleted?)
end

#page?Boolean

Is this node a page

Returns:

  • (Boolean)


51
52
53
# File 'app/models/cms/section_node.rb', line 51

def page?
  node_type == 'Cms::Page'
end

#parent_sectionObject Also known as: section

This is the parent section for this node For backwards compatiblity



9
10
11
# File 'app/models/cms/section_node.rb', line 9

def parent_section
  self.parent ? self.parent.node : nil
end

#scope_conditionObject

For acts_as_list. Specifies that position should be unique within a section.



25
26
27
# File 'app/models/cms/section_node.rb', line 25

def scope_condition
  ancestry ? "ancestry = '#{ancestry}'" : 'ancestry IS NULL'
end

#section=(new_section) ⇒ Object

For backwards compatiblity



16
17
18
# File 'app/models/cms/section_node.rb', line 16

def section=(new_section)
  self.parent = new_section.node
end

#section?Boolean

Is this node a section

Returns:

  • (Boolean)


46
47
48
# File 'app/models/cms/section_node.rb', line 46

def section?
  node_type == 'Cms::Section'
end

#visible?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'app/models/cms/section_node.rb', line 33

def visible?
  return false unless node
  return false if (node.respond_to?(:hidden?) && node.hidden?)
  return false if (node.respond_to?(:archived?) && node.archived?)
  return false if (node.respond_to?(:published?) && !node.published?)
  true
end