entities.rb
5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require_dependency 'api/entities'
module Api
module Entities
class Person < Profile
expose :orientacao_sexual, :identidade_genero, :transgenero, :etnia, :membro_conselho
expose :points do |person, options|
person.points if person.environment.plugin_enabled?('GamificationPlugin')
end
expose :level do |person, options|
person.level if person.environment.plugin_enabled?('GamificationPlugin')
end
expose :gamification_plugin_level_percent do |person, options|
person.gamification_plugin_level_percent if person.environment.plugin_enabled?('GamificationPlugin')
end
end
end
end
module Merit
class BadgeRules
include Merit::BadgeRulesMethods
CONFERENCE_RULES = {
comment_author_conferencia: [
{
action: 'comment#create',
default_threshold: 5,
to: :author,
value: lambda { |comment, author| author.present? ? author.conference_comments.count : 0 }
}
],
comment_received_conferencia: [
{
action: 'comment#create',
default_threshold: 5,
to: lambda {|comment| comment.source.author},
value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 }
}
],
article_author_conferencia: [
{
action: 'article#create',
default_threshold: 5,
to: :author,
value: lambda { |article, author| author.present? ? TextArticle.conference_articles.where(author_id: author.id).count : 0 }
},
],
positive_votes_received_conferencia: [
{
action: 'vote#create',
default_threshold: 5,
to: lambda {|vote| vote.voteable.author},
value: lambda { |vote, author| vote.voteable.profile.identifier == 'conferencia' ? Vote.where(voteable_id: Article.conference_articles.select("articles.id")).for_voteable(vote.voteable).where('vote > 0').count : 0 }
}
],
negative_votes_received_conferencia: [
{
action: 'vote#create',
default_threshold: 5,
to: lambda {|vote| vote.voteable.author},
value: lambda { |vote, author| (vote.voteable.profile.identifier == 'conferencia' and author.present?) ? Vote.where(voteable_id: Article.conference_articles.select("articles.id")).for_voteable(vote.voteable).where('vote < 0').count : 0 }
}
],
votes_performed_conferencia: [
{
action: 'vote#create',
default_threshold: 5,
to: lambda {|vote| vote.voter},
value: lambda { |vote, voter| (vote.voteable.profile.identifier == 'conferencia' and voter.present?) ? Vote.where(voteable_id: Article.conference_articles.select("articles.id")).for_voter(voter).count : 0}
}
],
creative_conferencia: [
{
action: 'comment#create',
default_threshold: 5,
to: :author,
value: lambda { |comment, author| author.present? ? author.conference_comments.count : 0 }
},
{
action: 'article#create',
default_threshold: 5,
to: :author,
value: lambda { |article, author| author.present? ? TextArticle.conference_articles.where(author_id: author.id).count : 0 }
},
],
observer_conferencia: [
{
action: 'articlefollower#create',
default_threshold: 5,
to: :person,
model: 'ArticleFollower',
value: lambda { |article, person| person.present? ? person.article_followers.where(article_id: Article.conference_articles).count : 0 }
}
],
#activist_conferencia: [
#{
#action: 'Vote#create',
#default_threshold: 5,
#to: lambda { |vote| vote.voter },
#value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0 }
#},
#{
#action: 'Event#create',
#default_threshold: 5,
#to: lambda { |event| event.author },
#value: lambda { |event, author| author.events.count }
#},
#],
#mobilizer_conferencia: [
#{
#action: 'Vote#create',
#default_threshold: 5,
#to: lambda { |vote| vote.voter },
#value: lambda { |vote, voter| vote.voteable.profile.identifier == 'conferencia' ? Vote.for_voter(voter).count : 0 }
#},
#{
#action: 'Event#create',
#default_threshold: 5,
#to: lambda { |event| event.author },
#value: lambda { |event, author| author.events.count }
#},
#],
generous_conferencia: [
{
action: 'vote#create',
default_threshold: 5,
to: lambda {|vote| vote.voter},
value: lambda { |vote, voter| voter.present? ? voter.votes.where('vote > 0').where('voteable_id' => Article.conference_articles, 'voteable_type' => 'Article').count : 0 }
},
{
action: 'comment#create',
default_threshold: 5,
to: :author,
value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 }
}
],
articulator_conferencia: [
{
action: 'articlefollower#create',
default_threshold: 5,
to: :person,
model: 'ArticleFollower',
value: lambda { |article, person| person.present? ? person.article_followers.where(article_id: Article.conference_articles).count : 0 }
},
{
action: 'comment#create',
default_threshold: 5,
to: :author,
value: lambda { |comment, author| author.present? ? Comment.where(source_id: Article.conference_articles.where(author_id: author.id)).count : 0 }
},
#mobilizer#create
]
}
end
end