-
Notifications
You must be signed in to change notification settings - Fork 41
/
page_renderer.rb
86 lines (63 loc) · 2.93 KB
/
page_renderer.rb
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
# Copyright (C) 2010 Cykod LLC
#
#
class UserProfile::PageRenderer < ParagraphRenderer
features '/user_profile/page_feature'
paragraph :display_profile
paragraph :list_profiles
def display_profile
@options = paragraph_options(:display_profile)
@user_profile = find_profile
is_myself = @user_profile && @user_profile.end_user == myself
display_string = is_myself ? 'myself' : 'other'
result = renderer_cache(@user_profile,display_string, :skip => true) do |cache|
if @user_profile
@profile_user = @user_profile.end_user
@content_model = @user_profile.content_model
@user_profile_type = @user_profile.user_profile_type
cache[:full_name] = @profile_user.full_name if @profile_user
end
@url = site_node.node_path
cache[:output] = user_profile_page_display_profile_feature
end
if @user_profile
set_title(result.full_name)
set_title(result.full_name,"profile")
set_page_connection(:profile_content, @user_profile)
set_page_connection(:profile_myself, is_myself ? @user_profile : nil)
set_page_connection(:user_target, @user_profile.end_user )
set_page_connection(:user_content, [ "EndUser", @user_profile.end_user_id ])
set_content_node(@user_profile)
end
render_paragraph :text => result.output
end
@@profile_order_by_options = { 'newest' => 'end_users.created_at DESC',
'updated' => 'end_users.updated_at DESC',
'alpha' => 'end_users.last_name, end_users.first_name' }
def list_profiles
@options = paragraph_options(:list_profiles)
result = renderer_cache(UserProfileEntry,params[:page].to_s,:expires => 600) do |cache|
@user_profile_type = UserProfileType.find_by_id(@options.profile_type_id)
return render_paragraph :text => 'Configure Paragraph'.t if !@user_profile_type
order_by = @@profile_order_by_options[@options.order_by]
@pages,@users = @user_profile_type.paginate_users(params[:page],:order => order_by, :per_page => @options.per_page, :registered => @options.registered_only, :per_page => @options.per_page)
@content_model = @user_profile_type.content_model
cache[:output] = user_profile_page_list_profiles_feature
end
render_paragraph :text => result.output
end
def find_profile
if editor?
UserProfileEntry.find(:first,:conditions => { :user_profile_type_id => @options.profile_type_id})
else
conn_type,url = page_connection(:user_profile)
if url.blank? && @options.default_to_user
UserProfileEntry.find_by_end_user_id_and_user_profile_type_id(myself.id, @options.profile_type_id) ||
UserProfileEntry.fetch_first_entry(myself,@options.profile_type_id)
else
profile = UserProfileEntry.find_by_url_and_user_profile_type_id(url, @options.profile_type_id)
profile && profile.published? ? profile : nil
end
end
end
end