#23 Ensure the user field is always shown when repositioning elements

This commit is contained in:
Mark Nelson 2016-08-23 17:07:10 +08:00
parent ff049e2c1b
commit 761a8f3e57

View file

@ -125,17 +125,22 @@ class element extends \mod_customcert\element {
// The user field to display. // The user field to display.
$field = $this->element->data; $field = $this->element->data;
// The value to display on the PDF. // The value to display - we always want to show a value here so it can be repositioned.
$value = ''; $value = $field;
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))) {
// Found the field name, let's update the value to display.
$value = $field->name;
$file = $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php'; $file = $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php';
if (file_exists($file)) { if (file_exists($file)) {
require_once($CFG->dirroot . '/user/profile/lib.php'); require_once($CFG->dirroot . '/user/profile/lib.php');
require_once($file); require_once($file);
$class = "profile_field_{$field->datatype}"; $class = "profile_field_{$field->datatype}";
$field = new $class($field->id, $USER->id); $field = new $class($field->id, $USER->id);
$value = $field->display_data(); if ($fieldvalue = $field->display_data()) {
// Ok, found a value for the user, let's show that instead.
$value = $fieldvalue;
}
} }
} }
} else if (!empty($USER->$field)) { // Field in the user table. } else if (!empty($USER->$field)) { // Field in the user table.