Commit e5dea1dde9b85bc35baee689123a3692fa88d951
1 parent
175e64b7
Exists in
master
Add conference specific badges rules
Showing
3 changed files
with
142 additions
and
0 deletions
Show diff stats
lib/ext/article.rb
lib/ext/entities.rb
... | ... | @@ -11,3 +11,140 @@ module Noosfero |
11 | 11 | end |
12 | 12 | end |
13 | 13 | end |
14 | + | |
15 | +module Merit | |
16 | + class BadgeRules | |
17 | + include Merit::BadgeRulesMethods | |
18 | + | |
19 | + CONFERENCE_RULES = { | |
20 | + comment_author_conferencia: [ | |
21 | + { | |
22 | + action: 'comment#create', | |
23 | + default_threshold: 5, | |
24 | + to: :author, | |
25 | + value: lambda { |comment, author| author.present? ? author.conference_comments.count : 0 } | |
26 | + } | |
27 | + ], | |
28 | + comment_received_conferencia: [ | |
29 | + { | |
30 | + action: 'comment#create', | |
31 | + default_threshold: 5, | |
32 | + to: lambda {|comment| comment.source.author}, | |
33 | + value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 } | |
34 | + } | |
35 | + ], | |
36 | + article_author_conferencia: [ | |
37 | + { | |
38 | + action: 'article#create', | |
39 | + default_threshold: 5, | |
40 | + to: :author, | |
41 | + value: lambda { |article, author| author.present? ? TextArticle.conference_articles.where(author_id: author.id).count : 0 } | |
42 | + }, | |
43 | + ], | |
44 | + positive_votes_received_conferencia: [ | |
45 | + { | |
46 | + action: 'vote#create', | |
47 | + default_threshold: 5, | |
48 | + to: lambda {|vote| vote.voteable.author}, | |
49 | + value: lambda { |vote, author| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voteable(vote.voteable).where('vote > 0').count : 0 } | |
50 | + } | |
51 | + ], | |
52 | + negative_votes_received_conferencia: [ | |
53 | + { | |
54 | + action: 'vote#create', | |
55 | + default_threshold: 5, | |
56 | + to: lambda {|vote| vote.voteable.author}, | |
57 | + value: lambda { |vote, author| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voteable(vote.voteable).where('vote < 0').count : 0 } | |
58 | + } | |
59 | + ], | |
60 | + votes_performed_conferencia: [ | |
61 | + { | |
62 | + action: 'vote#create', | |
63 | + default_threshold: 5, | |
64 | + to: lambda {|vote| vote.voter}, | |
65 | + value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0} | |
66 | + } | |
67 | + ], | |
68 | + creative_conferencia: [ | |
69 | + { | |
70 | + action: 'comment#create', | |
71 | + default_threshold: 5, | |
72 | + to: :author, | |
73 | + value: lambda { |comment, author| author.present? ? author.conference_comments.count : 0 } | |
74 | + }, | |
75 | + { | |
76 | + action: 'article#create', | |
77 | + default_threshold: 5, | |
78 | + to: :author, | |
79 | + value: lambda { |article, author| author.present? ? TextArticle.conference_articles.where(author_id: author.id).count : 0 } | |
80 | + }, | |
81 | + ], | |
82 | + observer_conferencia: [ | |
83 | + { | |
84 | + action: 'article_follower#create', | |
85 | + default_threshold: 5, | |
86 | + to: :person, | |
87 | + value: lambda { |article, person| person.present? ? person.article_followers.where(article_id: Article.conference_articles).count : 0 } | |
88 | + } | |
89 | + ], | |
90 | + #activist_conferencia: [ | |
91 | + #{ | |
92 | + #action: 'Vote#create', | |
93 | + #default_threshold: 5, | |
94 | + #to: lambda { |vote| vote.voter }, | |
95 | + #value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0 } | |
96 | + #}, | |
97 | + #{ | |
98 | + #action: 'Event#create', | |
99 | + #default_threshold: 5, | |
100 | + #to: lambda { |event| event.author }, | |
101 | + #value: lambda { |event, author| author.events.count } | |
102 | + #}, | |
103 | + #], | |
104 | + #mobilizer_conferencia: [ | |
105 | + #{ | |
106 | + #action: 'Vote#create', | |
107 | + #default_threshold: 5, | |
108 | + #to: lambda { |vote| vote.voter }, | |
109 | + #value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0 } | |
110 | + #}, | |
111 | + #{ | |
112 | + #action: 'Event#create', | |
113 | + #default_threshold: 5, | |
114 | + #to: lambda { |event| event.author }, | |
115 | + #value: lambda { |event, author| author.events.count } | |
116 | + #}, | |
117 | + #], | |
118 | + generous_conferencia: [ | |
119 | + { | |
120 | + action: 'vote#create', | |
121 | + default_threshold: 5, | |
122 | + to: lambda {|vote| vote.voter}, | |
123 | + value: lambda { |vote, voter| voter.present? ? voter.votes.where('vote > 0').where('voteable_id' => Article.conference_articles, 'voteable_type' => 'Article').count : 0 } | |
124 | + }, | |
125 | + { | |
126 | + action: 'comment#create', | |
127 | + default_threshold: 5, | |
128 | + to: :author, | |
129 | + value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 } | |
130 | + } | |
131 | + ], | |
132 | + articulator_conferencia: [ | |
133 | + { | |
134 | + action: 'article_follower#create', | |
135 | + default_threshold: 5, | |
136 | + to: :person, | |
137 | + value: lambda { |article, person| person.present? ? person.article_followers.where(article_id: Article.conference_articles).count : 0 } | |
138 | + }, | |
139 | + { | |
140 | + action: 'comment#create', | |
141 | + default_threshold: 5, | |
142 | + to: :author, | |
143 | + value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 } | |
144 | + }, | |
145 | + #mobilizer#create | |
146 | + ] | |
147 | + } | |
148 | + | |
149 | + end | |
150 | +end | ... | ... |
lib/ext/person.rb