Class: Topic

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

Instance Method Summary collapse

Instance Method Details

#bodyObject


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

def body
  sb_posts.first
end

#editable_by?(user) ⇒ Boolean


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

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

#hit!Object


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

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

#last_pageObject


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

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

#notify_of_new_post(post) ⇒ Object


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

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


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

def paged?() sb_posts_count > 25 end

#sticky?Boolean


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

def sticky?() sticky == 1 end

#to_paramObject


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

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

#viewsObject


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

def views() hits end

#voicesObject


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

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