Skip to content

Commit

Permalink
FEATURE: sharing badges (nice share, good share, great share)
Browse files Browse the repository at this point in the history
FIX: bad translation
  • Loading branch information
SamSaffron committed Sep 11, 2014
1 parent 7f3797b commit 43e132d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
19 changes: 19 additions & 0 deletions app/models/badge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Badge < ActiveRecord::Base
NiceTopic = 18
GoodTopic = 19
GreatTopic = 20
NiceShare = 21
GoodShare = 22
GreatShare = 23

# other consts
AutobiographerMinBioLength = 10
Expand Down Expand Up @@ -187,6 +190,22 @@ def self.trust_level(level)
)
"
end

def self.sharing_badge(count)
<<SQL
SELECT views.user_id, i2.post_id, i2.created_at granted_at
FROM
(
SELECT i.user_id, MIN(i.id) i_id
FROM incoming_links i
JOIN badge_posts p on p.id = i.post_id
WHERE i.user_id IS NOT NULL
GROUP BY i.user_id,i.post_id
HAVING COUNT(*) > #{count}
) as views
JOIN incoming_links i2 ON i2.id = views.i_id
SQL
end
end

belongs_to :badge_type
Expand Down
13 changes: 11 additions & 2 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2184,12 +2184,21 @@ en:
nice_topic:
name: Nice Topic
description: Received 10 likes on a topic. This badge can be granted multiple times
good_post:
good_topic:
name: Good Topic
description: Received 25 likes on a topic. This badge can be granted multiple times
great_post:
great_topic:
name: Great Topic
description: Received 50 likes on a topic. This badge can be granted multiple times
nice_share:
name: Nice Share
description: Shared a post with 25 unique visitors
good_share:
name: Good Share
description: Shared a post with 300 unique visitors
great_share:
name: Great Share
description: Shared a post with 1000 unique visitors
first_like:
name: First Like
description: Liked a post
Expand Down
22 changes: 22 additions & 0 deletions db/fixtures/006_badges.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@
b.system = true
end

[
[Badge::NiceShare, "Nice Share", BadgeType::Bronze, 25],
[Badge::GoodShare, "Good Share", BadgeType::Silver, 300],
[Badge::GreatShare, "Great Share", 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.sharing_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.seed do |b|
b.id = Badge::Welcome
b.default_name = "Welcome"
Expand Down

0 comments on commit 43e132d

Please sign in to comment.