announcement-test/app/models/announcement_setting.rb

18 lines
491 B
Ruby
Raw Normal View History

class AnnouncementSetting
include Mongoid::Document
include Mongoid::Timestamps
field :top_limit, type: Integer, :default => 0
field :pro_enabled, type: Boolean, :default => false
def self.check_limit_for_user(user_id, b_id = nil)
2015-12-22 11:52:35 +00:00
limit = self.first.top_limit rescue 0
return true if limit == 0
count = Bulletin.where(:is_top => true, :create_user_id => user_id, :id.ne => b_id).count
return count < limit
end
def self.is_pro?
self.first.pro_enabled rescue false
end
end