Skip to content

Commit

Permalink
User Profile list
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Oct 6, 2010
1 parent 7557779 commit 5295e51
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,44 @@ class UserProfile::PageController < ParagraphController

editor_for :display_profile, :name => "Display Profile", :feature => :user_profile_page_display_profile, :inputs => { :user_profile => [ [:url, 'User URL', :path]] }, :outputs => [ [ :profile_content, "Profile Entry",:content] ]

editor_for :list_profiles, :name => 'List Profiles', :feature => :user_profile_page_list_profiles


class DisplayProfileOptions < HashModel
# this needs to be set as a paragraph option.. they have to pick which profile they want displayed on the page
attributes :profile_type_id => nil, :default_to_user => true
page_options :profile_type_id
boolean_options :default_to_user

validates_presence_of :profile_type_id

options_form(fld(:profile_type_id,:select,:options => :profile_type_select_options),
fld(:default_to_user,:radio_buttons,:options => :yes_no))
fld(:default_to_user,:yes_no))

def profile_type_select_options
UserProfileType.select_options_with_nil
end
def yes_no
[["Yes".t,true],["No".t,false]]
end


class ListProfilesOptions < HashModel
attributes :profile_type_id => nil, :order_by => 'newest', :registered_only => true, :per_page => 20

validates_presence_of :profile_type_id
integer_options :per_page
boolean_options :registered_only


has_options :order_by, [['Newest','newest'],['Updated','updated'],['Alphabetical','alpha']]

options_form(fld(:profile_type_id,:select,:options => :profile_type_select_options),
fld(:order_by,:select, :options => :order_by_select_options),
fld(:per_page,:text_field),
fld(:registered_only,:yes_no,:description => 'Only show registered users (recommended)'))

def profile_type_select_options
UserProfileType.select_options_with_nil
end

end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ def user_profile_page_display_profile_feature(data)
end
end


feature :user_profile_page_list_profiles, :default_feature => <<-FEATURE
<cms:users>
<ul class='users'>
<cms:user>
<li>
<img align='left'>
<h2><cms:link><cms:name/></cms:link></h2>
</li>
</cms:user>
</ul>
<cms:pages/>
</cms:users>
FEATURE


def user_profile_page_list_profiles_feature(data)
webiva_custom_feature(:user_profile_page_list_profiles,data) do |c|
c.loop_tag('user') { |t| data[:users] }
c.user_details_tags('user') { |t| t.locals.user.end_user }
c.link_tag('user:') { |t| data[:user_profile_type].content_type.content_link(t.locals.user) }
c.expansion_tag('user:profile') { |t| t.locals.entry = t.locals.user.content_model_entry if data[:content_model] }

c.content_model_fields_value_tags('user:profile',data[:user_profile_type].display_content_model_fields) if data[:content_model]
c.pagelist_tag('pages') { |t| data[:pages] }
end
end

feature :user_profile_page_profile_privacy, :default_feature => <<-FEATURE
<cms:user>
<cms:name/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,57 @@ 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


result = renderer_cache(@user_profile) 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
end

@url = site_node.node_path

cache[:output] = user_profile_page_display_profile_feature
end

if @user_profile
@profile_user = @user_profile.end_user
@content_model = @user_profile.content_model
@user_profile_type = @user_profile.user_profile_type
set_title(@profile_user.full_name)
set_title(@profile_user.full_name,"profile")
set_title(result.full_name)
set_title(result.full_name,"profile")
set_page_connection(:profile_content, ['UserProfileEntry',@user_profile.id])
set_content_node(@user_profile)
end

@url = site_node.node_path
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) 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, :registered => @options.registered_only)
@content_model = @user_profile_type.content_model

cache[:output] = user_profile_page_list_profiles_feature
end

render_paragraph :feature => :user_profile_page_display_profile
render_paragraph :text => result.output
end

def find_profile
Expand Down
5 changes: 5 additions & 0 deletions vendor/modules/user_profile/app/models/user_profile_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class UserProfileEntry < DomainModel
}
}

cached_content :identifier => :url

content_node(:container_type => 'UserProfileType', :container_field => 'user_profile_type_id', :push_value => true, :except => Proc.new() { |e| e.url.blank? })

Expand Down Expand Up @@ -78,6 +79,10 @@ def content_model_entry
@content_model_entry
end

def content_model_entry_cache=(val)
@content_model_entry = val
end

def create_full_name
self.end_user.full_name if self.end_user
end
Expand Down
33 changes: 33 additions & 0 deletions vendor/modules/user_profile/app/models/user_profile_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@ def self.import_fields
end


def paginate_users(page,options={})

if options[:registered_only]
conds = [ 'end_users.registered = 1']
else
conds = nil
end

pages,users = UserProfileEntry.paginate(page,:joins => [ :end_user ], :conditions => conds, :order => options[:order])


if self.content_model
cls = self.content_model.model_class

model_attributes = { self.content_model_field_name => users.map(&:end_user_id) }

model_entries = cls.find(:all,:conditions => model_attributes).index_by(&(self.content_model_field_name.to_sym))

users.each do |usr|
entry = model_entries[usr.end_user_id]
if entry
usr.content_model_entry_cache = entry
else
usr.content_model_entry_cache = cls.new( self.content_model_field_name => usr.end_user_id)
end
end
end

[ pages,users ]

end


protected

def update_user_classes
Expand Down

0 comments on commit 5295e51

Please sign in to comment.