person_api.rb
999 Bytes
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
class StoaPlugin::PersonApi < Noosfero::FieldsDecorator
def username
user.login
end
def nusp
usp_id
end
def first_name
name.split(' ').first
end
def surname
name.split(' ',2).last
end
def homepage
profile_homepage(context, object)
end
def birth_date
object.birth_date.present? ? object.birth_date.strftime('%F') : nil
end
def image_base64
Base64.encode64(image.current_data) if image && image.current_data
end
def tags
articles.published.tag_counts({:order => 'count desc', :limit => 10}).inject({}) do |memo,tag|
memo[tag.name] = tag.count
memo
end
end
def communities
object.communities.public.map {|community| {:url => profile_homepage(context, community), :name => community.name}}
end
private
def profile_homepage(context, profile)
if context.respond_to?(:url_for)
context.url_for(profile.url)
else
profile.environment.top_url + '/' + profile.identifier
end
end
end