class AnnouncementTag < Tag
  
  has_and_belongs_to_many :bulletins
  field :order,:default => 0  
  
  def get_visible_bulletins(sort = :title)
    date_now = Time.now
    self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort)
  end
  
  def bulletins
    Bulletin.all.any_in(:_id => bulletin_ids)
  end

end