mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Merge branch 'MDL-77967-main' of https://github.com/rmady/moodle
This commit is contained in:
commit
b64dff686e
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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']);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user