Merge branch 'MDL-77967-main' of https://github.com/rmady/moodle

This commit is contained in:
Andrew Nicols 2024-04-11 13:56:54 +08:00
commit b64dff686e
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
3 changed files with 39 additions and 3 deletions

View File

@ -394,7 +394,7 @@ function user_get_user_details($user, $course = null, array $userfields = array(
foreach ($fields as $formfield) {
if ($formfield->show_field_content()) {
$userdetails['customfields'][] = [
'name' => $formfield->field->name,
'name' => $formfield->display_name(),
'value' => $formfield->data,
'displayvalue' => $formfield->display_data(),
'type' => $formfield->field->datatype,

View File

@ -146,6 +146,17 @@ class profile_field_base {
return format_text($this->data, FORMAT_MOODLE, $options);
}
/**
* Display the name of the profile field.
*
* @return string
*/
public function display_name() {
$options = new stdClass();
$options->para = false;
return format_text($this->field->name, FORMAT_MOODLE, $options);
}
/**
* Print out the form field in the edit profile page
* @param MoodleQuickForm $mform instance of the moodleform class

View File

@ -188,11 +188,14 @@ class externallib_test extends externallib_advanced_testcase {
// Create complex user profile field supporting multi-lang.
filter_set_global_state('multilang', TEXTFILTER_ON);
$name = '<span lang="en" class="multilang">Employment status</span>'.
'<span lang="es" class="multilang">Estado de Empleo</span>';
$statuses = 'UE\nSE\n<span lang="en" class="multilang">Other</span><span lang="es" class="multilang">Otro</span>';
$generator->create_custom_profile_field(
[
'datatype' => 'menu',
'shortname' => 'employmentstatus', 'name' => 'Employment status',
'shortname' => 'employmentstatus',
'name' => $name,
'param1' => $statuses
]
);
@ -311,6 +314,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertCount(1, $returneduser['customfields']);
$dbvalue = explode('\n', $statuses)[2];
$this->assertEquals($dbvalue, $returneduser['customfields'][0]['value']);
$this->assertEquals('Employment status', $returneduser['customfields'][0]['name']);
$this->assertEquals('Other', $returneduser['customfields'][0]['displayvalue']);
}
}
@ -346,6 +350,21 @@ class externallib_test extends externallib_advanced_testcase {
$return = new \stdClass();
$generator = self::getDataGenerator();
// Create complex user profile field supporting multi-lang.
filter_set_global_state('multilang', TEXTFILTER_ON);
$name = '<span lang="en" class="multilang">Employment status</span>'.
'<span lang="es" class="multilang">Estado de Empleo</span>';
$statuses = 'UE\nSE\n<span lang="en" class="multilang">Other</span><span lang="es" class="multilang">Otro</span>';
$generator->create_custom_profile_field(
[
'datatype' => 'menu',
'shortname' => 'employmentstatus',
'name' => $name,
'param1' => $statuses
]
);
// Create the course and fetch its context.
$return->course = self::getDataGenerator()->create_course();
$return->user1 = array(
@ -362,7 +381,8 @@ class externallib_test extends externallib_advanced_testcase {
'description' => 'This is a description for user 1',
'descriptionformat' => FORMAT_MOODLE,
'city' => 'Perth',
'country' => 'AU'
'country' => 'AU',
'profile_field_employmentstatus' => explode('\n', $statuses)[2],
);
$return->user1 = self::getDataGenerator()->create_user($return->user1);
if (!empty($CFG->usetags)) {
@ -448,6 +468,11 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertEquals(FORMAT_HTML, $enrolleduser['descriptionformat']);
$this->assertEquals($data->user1->city, $enrolleduser['city']);
$this->assertEquals($data->user1->country, $enrolleduser['country']);
// Default language was used for the user.
$this->assertEquals($CFG->lang, $enrolleduser['lang']);
$this->assertEquals('Employment status', $enrolleduser['customfields'][0]['name']);
$this->assertEquals('Other', $enrolleduser['customfields'][0]['displayvalue']);
if (!empty($CFG->usetags)) {
$this->assertEquals(implode(', ', $data->user1->interests), $enrolleduser['interests']);
}