FEATURE: bronze/silver/gold badges for popular links
This commit is contained in:
parent
42e785ee5a
commit
d96531b163
|
@ -20,10 +20,12 @@ class Badge < ActiveRecord::Base
|
|||
GoodShare = 22
|
||||
GreatShare = 23
|
||||
OneYearAnniversary = 24
|
||||
|
||||
Promoter = 25
|
||||
Campaigner = 26
|
||||
Champion = 27
|
||||
PopularLink = 28
|
||||
HotLink = 29
|
||||
FamousLink = 30
|
||||
|
||||
# other consts
|
||||
AutobiographerMinBioLength = 10
|
||||
|
@ -244,6 +246,19 @@ SQL
|
|||
JOIN incoming_links i2 ON i2.id = views.i_id
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.linking_badge(count)
|
||||
<<-SQL
|
||||
SELECT tl.user_id, post_id, MIN(tl.created_at) granted_at
|
||||
FROM topic_links tl
|
||||
JOIN posts p ON p.id = post_id AND p.deleted_at IS NULL
|
||||
JOIN topics t ON t.id = p.topic_id AND t.deleted_at IS NULL AND t.archetype <> 'private_message'
|
||||
WHERE NOT tl.internal
|
||||
AND tl.clicks >= #{count}
|
||||
GROUP BY tl.user_id, tl.post_id
|
||||
SQL
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
belongs_to :badge_type
|
||||
|
|
|
@ -2706,6 +2706,15 @@ en:
|
|||
reader:
|
||||
name: Reader
|
||||
description: Read every post in a topic with more than 100 posts
|
||||
popular_link:
|
||||
name: Popular Link
|
||||
description: Posted an external link with at least 50 clicks
|
||||
hot_link:
|
||||
name: Hot Link
|
||||
description: Posted an external link with at least 300 clicks
|
||||
famous_link:
|
||||
name: Famous Link
|
||||
description: Posted an external link with at least 1000 clicks
|
||||
|
||||
google_search: |
|
||||
<h3>Search with Google</h3>
|
||||
|
|
|
@ -140,7 +140,6 @@ Badge.seed do |b|
|
|||
b.system = true
|
||||
end
|
||||
|
||||
|
||||
[
|
||||
[Badge::Promoter,"Promoter",BadgeType::Bronze,1,0],
|
||||
[Badge::Campaigner,"Campaigner",BadgeType::Silver,3,1],
|
||||
|
@ -245,7 +244,6 @@ like_badges = [
|
|||
{id: Badge::GreatTopic, name: "Great Topic", type: BadgeType::Gold, topic: true}
|
||||
]
|
||||
|
||||
|
||||
like_badges.each do |spec|
|
||||
Badge.seed do |b|
|
||||
b.id = spec[:id]
|
||||
|
@ -273,6 +271,27 @@ Badge.seed do |b|
|
|||
b.system = true
|
||||
end
|
||||
|
||||
[
|
||||
[Badge::PopularLink, "Popular Link", BadgeType::Bronze, 50],
|
||||
[Badge::HotLink, "Hot Link", BadgeType::Silver, 300],
|
||||
[Badge::FamousLink, "Famous Link", BadgeType::Gold, 1000],
|
||||
].each do |spec|
|
||||
id, name, level, count = spec
|
||||
Badge.seed do |b|
|
||||
b.id = id
|
||||
b.default_name = name
|
||||
b.badge_type_id = level
|
||||
b.multiple_grant = true
|
||||
b.target_posts = true
|
||||
b.show_posts = true
|
||||
b.query = Badge::Queries.linking_badge(count)
|
||||
b.default_badge_grouping_id = BadgeGrouping::Community
|
||||
# don't trigger for now, its too expensive
|
||||
b.trigger = Badge::Trigger::None
|
||||
b.system = true
|
||||
end
|
||||
end
|
||||
|
||||
Badge.where("NOT system AND id < 100").each do |badge|
|
||||
new_id = [Badge.maximum(:id) + 1, 100].max
|
||||
old_id = badge.id
|
||||
|
|
Loading…
Reference in New Issue