From 66643c0aa8d465418ec7433c70e30a5f5ed0ac48 Mon Sep 17 00:00:00 2001 From: ikawhero Date: Mon, 8 Oct 2007 07:21:32 +0000 Subject: [PATCH] New function to return a partial user object with the custom profile fields set. --- user/profile/lib.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/user/profile/lib.php b/user/profile/lib.php index 1d09efc31f7..eade89bd9a8 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -384,4 +384,27 @@ function profile_signup_fields(&$mform) { } } +/** + * Returns an object with the custom profile fields set for the given user + * @param integer userid + * @return object + */ +function profile_user_record($userid) { + global $CFG; + + $user = new object(); + + if ($fields = get_records_select('user_info_field')) { + foreach ($fields as $field) { + require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php'); + $newfield = 'profile_field_'.$field->datatype; + $formfield = new $newfield($field->id, $userid); + $user->{$field->shortname} = $formfield->data; + } + } + + return $user; +} + + ?>