FEATURE: new badges when visiting the forum for 10, 100 and 365 consecutive days
This commit is contained in:
parent
0fca5ed533
commit
8a935a4b5f
|
@ -56,6 +56,10 @@ class Badge < ActiveRecord::Base
|
||||||
GivesBack = 32
|
GivesBack = 32
|
||||||
Empathetic = 39
|
Empathetic = 39
|
||||||
|
|
||||||
|
Enthusiast = 45
|
||||||
|
Aficionado = 46
|
||||||
|
Devotee = 47
|
||||||
|
|
||||||
NewUserOfTheMonth = 44
|
NewUserOfTheMonth = 44
|
||||||
|
|
||||||
# other consts
|
# other consts
|
||||||
|
|
|
@ -3392,6 +3392,18 @@ en:
|
||||||
description: Outstanding contributions in their first month
|
description: Outstanding contributions in their first month
|
||||||
long_description: |
|
long_description: |
|
||||||
This badge is granted to congratulate two new users each month for their excellent overall contributions, as measured by how often their posts were liked, and by whom.
|
This badge is granted to congratulate two new users each month for their excellent overall contributions, as measured by how often their posts were liked, and by whom.
|
||||||
|
enthusiast:
|
||||||
|
name: Enthusiast
|
||||||
|
description: Has visited the forum for 10 consecutive days
|
||||||
|
long_description: This badge is granted the first time you visit the forum for 10 consecutive days.
|
||||||
|
aficionado:
|
||||||
|
name: Aficionado
|
||||||
|
description: Has visited the forum for 100 consecutive days
|
||||||
|
long_description: This badge is granted the first time you visit the forum for 100 consecutive days.
|
||||||
|
devotee:
|
||||||
|
name: Devotee
|
||||||
|
description: Has visited the forum for 365 consecutive days
|
||||||
|
long_description: This badge is granted the first time you visit the forum for 365 consecutive days.
|
||||||
badge_title_metadata: "%{display_name} badge on %{site_title}"
|
badge_title_metadata: "%{display_name} badge on %{site_title}"
|
||||||
|
|
||||||
admin_login:
|
admin_login:
|
||||||
|
|
|
@ -415,6 +415,25 @@ Badge.seed do |b|
|
||||||
b.system = true
|
b.system = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
[Badge::Enthusiast, "Enthusiast", BadgeType::Bronze, 10],
|
||||||
|
[Badge::Aficionado, "Aficionado", BadgeType::Silver, 100],
|
||||||
|
[Badge::Devotee, "Devotee", BadgeType::Gold, 365],
|
||||||
|
].each do |id, name, level, days|
|
||||||
|
Badge.seed do |b|
|
||||||
|
b.id = id
|
||||||
|
b.name = name
|
||||||
|
b.default_icon = "fa-eye"
|
||||||
|
b.badge_type_id = level
|
||||||
|
b.query = BadgeQueries.consecutive_visits(days)
|
||||||
|
b.badge_grouping_id = BadgeGrouping::Community
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Community
|
||||||
|
b.trigger = Badge::Trigger::None
|
||||||
|
b.auto_revoke = false
|
||||||
|
b.system = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Badge.where("NOT system AND id < 100").each do |badge|
|
Badge.where("NOT system AND id < 100").each do |badge|
|
||||||
new_id = [Badge.maximum(:id) + 1, 100].max
|
new_id = [Badge.maximum(:id) + 1, 100].max
|
||||||
old_id = badge.id
|
old_id = badge.id
|
||||||
|
|
|
@ -232,4 +232,16 @@ SQL
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.consecutive_visits(days)
|
||||||
|
<<~SQL
|
||||||
|
SELECT user_id, "start" + interval '1' day * COUNT(*) AS "granted_at"
|
||||||
|
FROM (
|
||||||
|
SELECT user_id, visited_at - (DENSE_RANK() OVER (PARTITION BY user_id ORDER BY visited_at))::int "start"
|
||||||
|
FROM user_visits
|
||||||
|
) s
|
||||||
|
GROUP BY user_id, "start"
|
||||||
|
HAVING COUNT(*) >= #{days}
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue