]> git.mjollnir.org Git - moodle.git/commitdiff
Placed the work behind printing out the categories and fields into a
authorikawhero <ikawhero>
Thu, 25 Jan 2007 05:20:10 +0000 (05:20 +0000)
committerikawhero <ikawhero>
Thu, 25 Jan 2007 05:20:10 +0000 (05:20 +0000)
function.

user/profile/lib.php

index c8206ca2a8d927f7ead2b15d673da1ee1cd6a1ce..552ffea9fc5138942590c565fc52477f036da2a2 100644 (file)
@@ -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