Class: SectionNode

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

Direct Known Subclasses

Link, Page, Section

Instance Method Summary collapse

Instance Method Details

#move_after(section_node) ⇒ Object



77
78
79
80
81
82
83
84
# File 'app/models/section_node.rb', line 77

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



68
69
70
71
72
73
74
75
# File 'app/models/section_node.rb', line 68

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(sec, pos) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/section_node.rb', line 46

def move_to(sec, pos)
  #logger.info "Moving Section Node ##{id} to Section ##{sec.id} Position #{pos}"
  transaction do
    if section != sec
      remove_from_list
      self.update_attribute(:parent, sec)
    end
    logger.info "dude: " + pos.to_s
    if pos < 0
      pos = 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 = sec.children.count
      pos = node_count if pos > node_count
    end
    logger.info "hans: " + pos.to_s
    insert_at_position(pos)
  end
end

#move_to_beginning(sec) ⇒ Object



86
87
88
# File 'app/models/section_node.rb', line 86

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

#move_to_end(sec) ⇒ Object



90
91
92
93
# File 'app/models/section_node.rb', line 90

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

#nodeObject

!!(groups.find_by_code(‘guest’))



117
118
119
# File 'app/models/section_node.rb', line 117

def node
  self
end

#page?Boolean

Is this node a page

Returns:

  • (Boolean)


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

def page?
  self.is_a?(Page)
end

#pathObject



123
124
125
# File 'app/models/section_node.rb', line 123

def path
  read_attribute :path
end

#public?Boolean

Proxy ############

Returns:

  • (Boolean)


110
111
112
113
114
115
116
# File 'app/models/section_node.rb', line 110

def public?
  groups.each{ |x|
    return true if x.code == "guest"
  }
  return false
  #!!(groups.find_by_code('guest'))
end

#root?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'app/models/section_node.rb', line 120

def root?
  is_root?
end

#sectionObject



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

def section
  self.parent
end

#section=(sec) ⇒ Object



139
140
141
# File 'app/models/section_node.rb', line 139

def section=(sec)
  self.parent = sec
end

#section?Boolean

Is this node a section

Returns:

  • (Boolean)


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

def section?
  self.is_a?(Section)
end

#section_idObject



127
128
129
# File 'app/models/section_node.rb', line 127

def section_id
  self.parent_id
end

#section_id=(sec_id) ⇒ Object



135
136
137
# File 'app/models/section_node.rb', line 135

def section_id=(sec_id)
  self.parent_id = sec_id
end

#visible?Boolean

named_scope :of_type, lambda{|types| {:conditions => [“section_nodes.node_type IN (?)”, types]}}

Returns:

  • (Boolean)


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

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