FEATURE: badges for inviting users

First invite = Promoter
3 TL2 = Campaigner
10 TL3 = Champion
This commit is contained in:
Sam 2015-05-15 12:04:41 +10:00
parent cb09c0d7a5
commit 2955507a57
3 changed files with 52 additions and 0 deletions

View File

@ -21,6 +21,10 @@ class Badge < ActiveRecord::Base
GreatShare = 23
OneYearAnniversary = 24
Promoter = 25
Campaigner = 26
Champion = 27
# other consts
AutobiographerMinBioLength = 10
@ -189,6 +193,22 @@ SQL
HAVING COUNT(p.id) > 0
SQL
def self.invite_badge(count,trust_level)
"
SELECT u.id user_id, current_timestamp granted_at
FROM users u
WHERE u.id IN (
SELECT invited_by_id
FROM invites i
JOIN users u2 ON u2.id = i.user_id
WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= #{trust_level.to_i} AND not u2.blocked
GROUP BY invited_by_id
HAVING COUNT(*) > #{count.to_i}
) AND u.active AND NOT u.blocked AND u.id > 0 AND
(:backfill OR u.id IN (:user_ids) )
"
end
def self.like_badge(count, is_topic)
# we can do better with dates, but its hard work
"

View File

@ -2521,6 +2521,15 @@ en:
first_flag:
name: First Flag
description: Flagged a post
promoter:
name: Promoter
description: Invited a user
campaigner:
name: Campaigner
description: Invited 3 members
champion:
name: Champion
description: Invited 10 members
first_share:
name: First Share
description: Shared a post

View File

@ -140,6 +140,29 @@ Badge.seed do |b|
b.system = true
end
[
[Badge::Promoter,"Promoter",BadgeType::Bronze,1,0],
[Badge::Campaigner,"Campaigner",BadgeType::Silver,3,2],
[Badge::Champion,"Champion",BadgeType::Gold,10,2],
].each do |id, name, type, count, trust_level|
Badge.seed do |b|
b.id = id
b.default_name = name
b.default_icon = "fa-user-plus"
b.badge_type_id = type
b.multiple_grant = false
b.target_posts = false
b.show_posts = false
b.query = Badge::Queries.invite_badge(count,trust_level)
b.default_badge_grouping_id = BadgeGrouping::Community
# daily is good enough
b.trigger = Badge::Trigger::None
b.auto_revoke = true
b.system = true
end
end
Badge.seed do |b|
b.id = Badge::FirstShare
b.default_name = "First Share"