Class: MongoidForums::Topic
Class Method Summary
collapse
Instance Method Summary
collapse
#register_view_by, #view_for
#alert_subscribers, #subscribe_creator, #subscribe_user, #subscriber?, #subscription_for, #unsubscribe_user
Class Method Details
.by_most_recent_post ⇒ Object
45
46
47
|
# File 'app/models/mongoid_forums/topic.rb', line 45
def by_most_recent_post
order_by([:last_post_at, :desc])
end
|
.by_pinned_or_most_recent_post ⇒ Object
49
50
51
|
# File 'app/models/mongoid_forums/topic.rb', line 49
def by_pinned_or_most_recent_post
order_by([:pinned, :desc], [:last_post_at, :desc])
end
|
Instance Method Details
#can_be_replied_to? ⇒ Boolean
23
24
25
|
# File 'app/models/mongoid_forums/topic.rb', line 23
def can_be_replied_to?
!locked?
end
|
#toggle!(field) ⇒ Object
27
28
29
30
|
# File 'app/models/mongoid_forums/topic.rb', line 27
def toggle!(field)
send "#{field}=", !self.send("#{field}?")
save :validation => false
end
|
#unread_post_count(user) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/models/mongoid_forums/topic.rb', line 32
def unread_post_count(user)
view = View.where(:viewable_id => id, :user_id => user.id).first
return posts.count unless view.present?
count = 0
posts.each do |post|
if post.created_at > view.current_viewed_at
count+=1
end
end
return count
end
|