From cfe18c3f5bc636b74012b03ff6f509f6c540faba Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 15 Mar 2016 14:46:21 -0400 Subject: [PATCH] FEATURE: Gives Back badge --- app/models/badge.rb | 11 +++++++++++ config/locales/client.en.yml | 3 +++ db/fixtures/006_badges.rb | 14 +++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/models/badge.rb b/app/models/badge.rb index e8a72c40b..dd01145ef 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -27,6 +27,7 @@ class Badge < ActiveRecord::Base HotLink = 29 FamousLink = 30 Admired = 31 + GivesBack = 32 # other consts AutobiographerMinBioLength = 10 @@ -207,6 +208,16 @@ SQL HAVING count(*)::float / us.post_count > 0.75 SQL + GivesBack = <<-SQL + SELECT us.user_id, current_timestamp AS granted_at + FROM user_stats AS us + INNER JOIN posts AS p ON us.user_id = p.user_id + WHERE p.like_count > 0 + AND (:backfill OR us.user_id IN (:user_ids)) + GROUP BY us.user_id + HAVING us.likes_given::float / count(*) > 5.0 +SQL + def self.invite_badge(count,trust_level) " SELECT u.id user_id, current_timestamp granted_at diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 05c4313bf..736e318b2 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -2967,6 +2967,9 @@ en: admired: name: Admired description: Has a high ratio of liked posts + gives_back: + name: Gives Back + description: Has a high ratio of likes given to likes received google_search: |

Search with Google

diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index 3fa022d1b..c4cf23c18 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -300,7 +300,19 @@ Badge.seed do |b| b.query = Badge::Queries::Admired b.default_badge_grouping_id = BadgeGrouping::Community b.trigger = Badge::Trigger::None - b.auto_revoke = true + b.auto_revoke = false + b.system = true +end + +Badge.seed do |b| + b.id = Badge::GivesBack + b.default_name = "Gives Back" + b.default_icon = "fa-heart" + b.badge_type_id = BadgeType::Silver + b.query = Badge::Queries::GivesBack + b.default_badge_grouping_id = BadgeGrouping::Community + b.trigger = Badge::Trigger::None + b.auto_revoke = false b.system = true end