Class: Topic

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

Instance Method Summary collapse

Instance Method Details

#bodyObject



38
39
40
# File 'app/models/topic.rb', line 38

def body
  sb_posts.first
end

#editable_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/topic.rb', line 56

def editable_by?(user)
  user && (user.id == user_id || user.admin? || user.moderator_of?(forum_id))
end

#hit!Object



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

def hit!
  self.class.increment_counter :hits, id
end

#last_pageObject



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

def last_page
  (sb_posts_count.to_f / 25.0).ceil.to_i
end

#notify_of_new_post(post) ⇒ Object



24
25
26
27
28
# File 'app/models/topic.rb', line 24

def notify_of_new_post(post)
  monitorships.each do |m|
    UserNotifier.new_forum_post_notice(m.user, post).deliver if (m.user != post.user) && m.user.notify_comments
  end
end

#paged?Boolean

Returns:

  • (Boolean)


50
# File 'app/models/topic.rb', line 50

def paged?() sb_posts_count > 25 end

#sticky?Boolean

Returns:

  • (Boolean)


46
# File 'app/models/topic.rb', line 46

def sticky?() sticky == 1 end

#to_paramObject



30
31
32
# File 'app/models/topic.rb', line 30

def to_param
  id.to_s << "-" << (title ? title.parameterize : '' )
end

#viewsObject



48
# File 'app/models/topic.rb', line 48

def views() hits end

#voicesObject



34
35
36
# File 'app/models/topic.rb', line 34

def voices
  sb_posts.map { |p| p.user_id }.uniq.size
end