#26 Fixed userfields not displaying data correctly

This commit is contained in:
Mark Nelson 2016-08-22 12:56:11 +08:00
parent 65aee9c9c0
commit a3fb3a7af4

View file

@ -113,7 +113,7 @@ class element extends \mod_customcert\element {
* drag and drop interface to position it. * drag and drop interface to position it.
*/ */
public function render_html() { public function render_html() {
global $DB, $USER; global $CFG, $DB, $USER;
// The user field to display. // The user field to display.
$field = $this->element->data; $field = $this->element->data;
@ -121,7 +121,14 @@ class element extends \mod_customcert\element {
$value = ''; $value = '';
if (is_number($field)) { // Must be a custom user profile field. if (is_number($field)) { // Must be a custom user profile field.
if ($field = $DB->get_record('user_info_field', array('id' => $field))) { if ($field = $DB->get_record('user_info_field', array('id' => $field))) {
$value = $USER->profile[$field->shortname]; $file = $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
if (file_exists($file)) {
require_once($CFG->dirroot . '/user/profile/lib.php');
require_once($file);
$class = "profile_field_{$field->datatype}";
$field = new $class($field->id, $USER->id);
$value = $field->display_data();
}
} }
} else if (!empty($USER->$field)) { // Field in the user table. } else if (!empty($USER->$field)) { // Field in the user table.
$value = $USER->$field; $value = $USER->$field;