From 9229c9a88362c528ca8049cd6de890f8e51f2e75 Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Thu, 29 May 2008 16:51:11 +0000 Subject: [PATCH] Added tmpl_vars for files to UserList --- lib/WebGUI/Asset/Wobject/UserList.pm | 56 +++++++++++++++++++++-- lib/WebGUI/Help/Asset_UserList.pm | 2 + lib/WebGUI/i18n/English/Asset_UserList.pm | 12 +++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/UserList.pm b/lib/WebGUI/Asset/Wobject/UserList.pm index 8ef1416fb..7d8ea0bc3 100644 --- a/lib/WebGUI/Asset/Wobject/UserList.pm +++ b/lib/WebGUI/Asset/Wobject/UserList.pm @@ -13,6 +13,7 @@ use WebGUI::Operation::Shared; use WebGUI::International; use WebGUI::Pluggable; use WebGUI::Form::Image; +use WebGUI::Form::File; use base 'WebGUI::Asset::Wobject'; =head1 LEGAL @@ -70,6 +71,48 @@ sub getAlphabetSearchLoop { #------------------------------------------------------------------- +=head2 getFieldValue ( value, field ) + +Processes the field value for date(Time) fields and Other Thing fields. + +=head3 value + +The value as stored in the database. + +=head3 field + +A reference to a hash containing the fields properties. + +=cut + +sub getFieldValue { + + my $self = shift; + my $value = shift; + my $field = shift; + my $dateFormat = shift || "%z"; + my $dateTimeFormat = shift; + my $processedValue = $value; + + if ($field->{fieldType} eq "date"){ + $processedValue = $self->session->datetime->epochToHuman($value,$dateFormat); + } + elsif ($field->{fieldType} eq "dateTime"){ + $processedValue = $self->session->datetime->epochToHuman($value,$dateTimeFormat); + } + elsif (WebGUI::Utility::isIn(ucfirst $field->{fieldType},qw(File Image))) { + $processedValue = WebGUI::Form::DynamicField->new($self->session, + fieldType=>$field->{fieldType}, + value=>$value + )->getValueAsHtml(); + } + + return $processedValue; + +} + +#------------------------------------------------------------------- + =head2 getFormElement ( data ) Returns the form element tied to this field. @@ -514,10 +557,17 @@ sub view { $profileFieldName =~ s/ /_/g; $profileFieldName =~ s/\./_/g; my $value = $user->{$profileField->{fieldName}}; + my %profileFieldValues; + if (WebGUI::Utility::isIn(ucfirst $profileField->{fieldType},qw(File Image)) && $value ne ''){ + my $file = $self->getFieldValue($value,{ + fieldType=>$profileField->{fieldType} + }); + $profileFieldValues{profile_file} = $file; + $userProperties{'user_profile_'.$profileFieldName.'_file'} = $file; + } + $profileFieldValues{profile_value} = $value; if($profileField->{visible}){ - push (@profileFieldValues, { - "profile_value"=>$value, - }); + push (@profileFieldValues, \%profileFieldValues); } unless($self->get("showOnlyVisibleAsNamed") && $profileField->{visible} != 1){ $userProperties{'user_profile_'.$profileFieldName.'_value'} = $value; diff --git a/lib/WebGUI/Help/Asset_UserList.pm b/lib/WebGUI/Help/Asset_UserList.pm index 73f7d3d8b..83d39fae0 100644 --- a/lib/WebGUI/Help/Asset_UserList.pm +++ b/lib/WebGUI/Help/Asset_UserList.pm @@ -54,11 +54,13 @@ our $HELP = { { 'name' => 'user_name' }, { 'name' => 'user_id' }, { 'name' => 'user_profile_PROFILEFIELDNAME_value' }, + { 'name' => 'user_profile_PROFILEFIELDNAME_file' }, { 'name' => 'user_profile_emailNotPublic' }, { 'name' => 'user_profile_loop', 'variables' => [ { 'name' => 'profile_emailNotPublic' }, { 'name' => 'profile_value' }, + { 'name' => 'profile_file' }, ], }, ], diff --git a/lib/WebGUI/i18n/English/Asset_UserList.pm b/lib/WebGUI/i18n/English/Asset_UserList.pm index 01fcc8543..cac9a56fb 100644 --- a/lib/WebGUI/i18n/English/Asset_UserList.pm +++ b/lib/WebGUI/i18n/English/Asset_UserList.pm @@ -300,6 +300,13 @@ profile. Example <tmpl_var user_profile_firstName_value>|, lastUpdated => 1081514049 }, + 'user_profile_PROFILEFIELDNAME_file' => { + message => q|The file for the profile field with the name PROFILEFIELDNAME in the users user +profile. Example <tmpl_var user_profile_firstName_file>. This is available if the profile field is a file or +an image.|, + lastUpdated => 1081514049 + }, + 'user_profile_emailNotPublic' => { message => q|A conditional that is true if the users email address is not public.|, lastUpdated => 1081514049 @@ -321,6 +328,11 @@ true for the 'email' profile field.|, lastUpdated => 1081514049 }, + 'profile_value' => { + message => q|The file for this profile field, available if the profile field is an image or file.|, + lastUpdated => 1081514049 + }, + 'profileField_loop' => { message => q|A loop containing profile fields|, lastUpdated => 1081514049