mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
Merge branch 'MDL-72019-master' of https://github.com/meirzamoodle/moodle
This commit is contained in:
commit
72145fc34d
@ -22,6 +22,8 @@
|
||||
* @package core
|
||||
*/
|
||||
|
||||
use core_user\fields;
|
||||
|
||||
define('NO_OUTPUT_BUFFERING', true);
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
@ -37,7 +39,7 @@ if (empty($SESSION->bulk_users)) {
|
||||
}
|
||||
|
||||
if ($dataformat) {
|
||||
$fields = array('id' => 'id',
|
||||
$originfields = array('id' => 'id',
|
||||
'username' => 'username',
|
||||
'email' => 'email',
|
||||
'firstname' => 'firstname',
|
||||
@ -51,8 +53,10 @@ if ($dataformat) {
|
||||
'country' => 'country');
|
||||
|
||||
$extrafields = profile_get_user_fields_with_data(0);
|
||||
$profilefields = [];
|
||||
foreach ($extrafields as $formfield) {
|
||||
$fields['profile_field_'.$formfield->get_shortname()] = 'profile_field_'.$formfield->get_shortname();
|
||||
$profilefields[fields::PROFILE_FIELD_PREFIX . $formfield->get_shortname()] = fields::PROFILE_FIELD_PREFIX .
|
||||
$formfield->get_shortname();
|
||||
}
|
||||
|
||||
$filename = clean_filename(get_string('users'));
|
||||
@ -60,17 +64,17 @@ if ($dataformat) {
|
||||
$downloadusers = new ArrayObject($SESSION->bulk_users);
|
||||
$iterator = $downloadusers->getIterator();
|
||||
|
||||
\core\dataformat::download_data($filename, $dataformat, $fields, $iterator, function($userid, $supportshtml)
|
||||
use ($extrafields, $fields) {
|
||||
\core\dataformat::download_data($filename, $dataformat, array_merge($originfields, $profilefields), $iterator,
|
||||
function($userid, $supportshtml) use ($originfields) {
|
||||
|
||||
global $DB;
|
||||
|
||||
if (!$user = $DB->get_record('user', array('id' => $userid))) {
|
||||
return null;
|
||||
}
|
||||
profile_load_data($user);
|
||||
|
||||
$userprofiledata = array();
|
||||
foreach ($fields as $field => $unused) {
|
||||
foreach ($originfields as $field) {
|
||||
// Custom user profile textarea fields come in an array
|
||||
// The first element is the text and the second is the format.
|
||||
// We only take the text.
|
||||
@ -82,6 +86,19 @@ if ($dataformat) {
|
||||
$userprofiledata[$field] = $user->$field;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Formatting extra field if transform is true.
|
||||
$extrafields = profile_get_user_fields_with_data($userid);
|
||||
foreach ($extrafields as $field) {
|
||||
$fieldkey = fields::PROFILE_FIELD_PREFIX . $field->get_shortname();
|
||||
if ($field->is_transform_supported()) {
|
||||
$userprofiledata[$fieldkey] = $field->display_data();
|
||||
} else {
|
||||
$userprofiledata[$fieldkey] = $field->data;
|
||||
}
|
||||
}
|
||||
|
||||
return $userprofiledata;
|
||||
});
|
||||
|
||||
|
@ -134,4 +134,13 @@ class profile_field_datetime extends profile_field_base {
|
||||
public function get_field_properties() {
|
||||
return array(PARAM_INT, NULL_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the field should convert the raw data into user-friendly data when exporting
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_transform_supported(): bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -582,6 +582,15 @@ class profile_field_base {
|
||||
public function get_field_properties() {
|
||||
return array(PARAM_RAW, NULL_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the field should convert the raw data into user-friendly data when exporting
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_transform_supported(): bool {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,11 @@
|
||||
This files describes API changes for code that uses the user API.
|
||||
|
||||
=== 4.1 ===
|
||||
|
||||
* Added a new method is_transform_supported() in the profile_field_base class.
|
||||
The purpose is to allow the field to be transformed during the export process.
|
||||
It has been implemented in the Date/Time data type (Applied in 4.1, 4.0.6).
|
||||
|
||||
* user_get_user_details_courses() now accepts an optional second parameter, an array of userfields that should be
|
||||
returned. The values passed into the $userfields parameter must all be included in the return from
|
||||
user_get_default_fields().
|
||||
|
Loading…
x
Reference in New Issue
Block a user