Hi,
I'm new in moodle and I want to get the branch, position and date hired of the user. But it seems that I only get only one record. I want to get all of this fields and display it to email confirmation.
This is all I've got:
function user_profile($user) {
global $CFG, $USER, $DB;
$userid = $user->id;
if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
foreach ($categories as $category) {
if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
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);
if ($formfield->is_visible() and !$formfield->is_empty()) {
echo "<dt>{$formfield->field->name}</dt>";
echo "<dd>{$formfield->display_data()}</dd>";
}
}
}
}
}
}
Output:
Branch: Alabang
I appreciate all the help I can get. Thank you.