From: ikawhero Date: Thu, 25 Jan 2007 05:20:10 +0000 (+0000) Subject: Placed the work behind printing out the categories and fields into a X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7240a6ea653bfa97830f6a9522ebedd15f259fa2;p=moodle.git Placed the work behind printing out the categories and fields into a function. --- diff --git a/user/profile/lib.php b/user/profile/lib.php index c8206ca2a8..552ffea9fc 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -454,6 +454,38 @@ class profile_field_base { /***** General purpose functions for customisable user profiles *****/ +/** + * Print out the customisable categories and fields for a users profile + * @param object instance of the moodleform class + * @param integer id of the user + * @return nothing + */ +function profile_print_custom_fields(&$form, $userid=0) { + global $USER, $CFG; + + if ($userid == 0) $userid = $USER->id; + + if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) { + foreach ($categories as $category) { + if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) { + + $form->addElement('header', 'category_'.$category->id, $category->name); + + 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,$user->id); + $formfield->display_field($form); + unset($formfield); + + } + } /// End of $fields if + } /// End of $categories foreach + } /// End of $categories if +} + + /** * Retrieve a list of all the available data types * @return array a list of the datatypes suitable to use in a select statement