diff --git a/app/models/badge.rb b/app/models/badge.rb index f4442cad380..72dabe630f4 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -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 diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index da3b03389ed..264c8b92996 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -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: |

Search with Google

diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index ed3af0bd97a..c96c0572ee4 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -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