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



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

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

#increment_posts_countObject



38
39
40
41
42
43
44
45
# File 'app/models/mongoid_forums/forum.rb', line 38

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

#moderator?(user) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
# File 'app/models/mongoid_forums/forum.rb', line 48

def moderator?(user)
  return false unless user
  return true if category.moderator?(user)
  moderator_groups.each do |group|
    return true if group.moderator && group.members.include?(user.id)
  end
  false
end

#moderatorsObject



57
58
59
60
61
62
63
# File 'app/models/mongoid_forums/forum.rb', line 57

def moderators
  array = Array.new
  self.moderator_groups.each do |g|
    array << g.group.members
  end
  return array
end

#unread_topic_count(user) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/mongoid_forums/forum.rb', line 22

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