Class: MongoidForums::Forum

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Concerns::Viewable
Defined in:
app/models/mongoid_forums/forum.rb

Instance Method Summary collapse

Methods included from Concerns::Viewable

#register_view_by, #view_for

Instance Method Details

#count_of_postsObject



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

def count_of_posts
  topics.inject(0) {|sum, topic| topic.posts.count + sum }
end

#increment_posts_countObject



33
34
35
36
37
38
39
40
# File 'app/models/mongoid_forums/forum.rb', line 33

def increment_posts_count
  if self.posts_count == nil
    self.posts_count = 1
  else
    self.posts_count += 1
  end
  self.save
end

#unread_topic_count(user) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/mongoid_forums/forum.rb', line 17

def unread_topic_count(user)
  view = View.where(:viewable_id => id, :user_id => user.id).first
  return topics.count unless view.present?
  count = 0
  topics.each do |topics|
    if topics.created_at > view.current_viewed_at
      count+=1
    end
  end
  return count
end