Sha256: d3d1376fa89d15e054559cbdc88867d34bcbf98c23f474b63344652a5bc5340c
Contents?: true
Size: 1.59 KB
Versions: 2
Compression:
Stored size: 1.59 KB
Contents
module MongoidForums class Forum include Mongoid::Document include MongoidForums::Concerns::Viewable belongs_to :category, :class_name => "MongoidForums::Category" validates :category, :presence => true has_many :topics, :class_name => "MongoidForums::Topic", dependent: :destroy # Caching field :posts_count, :type => Integer field :name validates :name, :presence => true has_and_belongs_to_many :moderator_groups, :class_name => "MongoidForums::Group", inverse_of: nil field :position, :type => Integer, :default => 0 validates :position, numericality: { only_integer: true } 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 def count_of_posts topics.inject(0) {|sum, topic| topic.posts.count + sum } end def increment_posts_count if self.posts_count == nil self.posts_count = 1 else self.posts_count += 1 end self.save end 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 def moderators array = Array.new self.moderator_groups.each do |g| array << g.group.members end return array end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid-forums-0.0.10 | app/models/mongoid_forums/forum.rb |
mongoid-forums-0.0.9 | app/models/mongoid_forums/forum.rb |