Class: Cms::SectionNode

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch_nodesObject



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

def fetch_nodes
  includes(:node)
end

.in_orderObject



36
37
38
# File 'app/models/cms/section_node.rb', line 36

def in_order
  order("position asc")
end

.not_of_type(klass) ⇒ Object

Return all section nodes which are not of the given type (i.e. class name)

Parameters:

  • klass (String)

    A specific class name that should be excluded.



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

def self.not_of_type(klass)
  where("#{table_name}.node_type NOT IN (?)", klass)
end

.of_type(types) ⇒ Object



32
33
34
# File 'app/models/cms/section_node.rb', line 32

def of_type(types)
  where(["#{table_name}.node_type IN (?)", types])
end

Instance Method Details

#ancestry_pathObject



141
142
143
# File 'app/models/cms/section_node.rb', line 141

def ancestry_path
  path_ids.join "/"
end

#deletable?Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
# File 'app/models/cms/section_node.rb', line 82

def deletable?
  return false if self.root?
  if node.respond_to?(:deletable?)
    return node.deletable?
  end
  true
end

#home?Boolean

Determines if this node is the homepage of the site.

Returns:

  • (Boolean)


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

def home?
  page? && node.home?
end

#link?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/cms/section_node.rb', line 78

def link?
  node_type == 'Cms::Link'
end

#move_after(section_node) ⇒ Object



123
124
125
126
127
128
129
130
# File 'app/models/cms/section_node.rb', line 123

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



114
115
116
117
118
119
120
121
# File 'app/models/cms/section_node.rb', line 114

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)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/cms/section_node.rb', line 92

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.where({:ancestry => ancestry}).count
      position = node_count if position > node_count
    end
    
    insert_at_position(position)
  end
end

#move_to_beginning(sec) ⇒ Object



132
133
134
# File 'app/models/cms/section_node.rb', line 132

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

#move_to_end(sec) ⇒ Object



136
137
138
139
# File 'app/models/cms/section_node.rb', line 136

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

#orphaned?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/cms/section_node.rb', line 64

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

#page?Boolean

Is this node a page

Returns:

  • (Boolean)


74
75
76
# File 'app/models/cms/section_node.rb', line 74

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

#parent_sectionObject Also known as: section

This is the parent section for this node For backwards compatiblity



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

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.



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

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

#section=(new_section) ⇒ Object

For backwards compatiblity



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

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

#section?Boolean

Is this node a section

Returns:

  • (Boolean)


69
70
71
# File 'app/models/cms/section_node.rb', line 69

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

#visible?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'app/models/cms/section_node.rb', line 56

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