ensures only one banner topic at all time

This commit is contained in:
Régis Hanol
2014-06-16 19:21:21 +02:00
parent 5238a95efb
commit 30611c343c
5 changed files with 68 additions and 26 deletions

View File

@ -626,6 +626,22 @@ class Topic < ActiveRecord::Base
end
end
def make_banner!(user)
# only one banner at the same time
previous_banner = Topic.where(archetype: Archetype.banner).first
previous_banner.remove_banner!(user) if previous_banner.present?
self.archetype = Archetype.banner
self.add_moderator_post(user, I18n.t("archetypes.banner.message.make"))
self.save
end
def remove_banner!(user)
self.archetype = Archetype.default
self.add_moderator_post(user, I18n.t("archetypes.banner.message.remove"))
self.save
end
def self.starred_counts_per_day(sinceDaysAgo=30)
TopicUser.starred_since(sinceDaysAgo).by_date_starred.count
end