MDL-67846 mod_forum: export user full name

This commit is contained in:
Simey Lameze
2020-02-25 15:26:22 +08:00
parent 37b2ee3f64
commit 041ff27245
+27 -10
View File
@@ -117,9 +117,11 @@ if ($form->is_cancelled()) {
$striphtml = !empty($data->striphtml);
$humandates = !empty($data->humandates);
$fields = ['id', 'discussion', 'parent', 'userid', 'created', 'modified', 'mailed', 'subject', 'message',
$fields = ['id', 'discussion', 'parent', 'userid', 'userfullname', 'created', 'modified', 'mailed', 'subject', 'message',
'messageformat', 'messagetrust', 'attachment', 'totalscore', 'mailnow', 'deleted', 'privatereplyto',
'wordcount', 'charcount'];
'privatereplytofullname', 'wordcount', 'charcount'];
$canviewfullname = has_capability('moodle/site:viewfullnames', $forum->get_context());
$datamapper = $legacydatamapperfactory->get_post_data_mapper();
$exportdata = new ArrayObject($datamapper->to_legacy_objects($posts));
@@ -132,8 +134,29 @@ if ($form->is_cancelled()) {
$dataformat,
$fields,
$iterator,
function($exportdata) use ($fields, $striphtml, $humandates) {
$data = $exportdata;
function($exportdata) use ($fields, $striphtml, $humandates, $canviewfullname) {
$data = new stdClass();
foreach ($fields as $field) {
// Set data field's value from the export data's equivalent field by default.
$data->$field = $exportdata->$field ?? null;
if ($field == 'userfullname') {
$user = \core_user::get_user($data->userid);
$data->userfullname = fullname($user, $canviewfullname);
}
if ($field == 'privatereplytofullname' && !empty($data->privatereplyto)) {
$user = \core_user::get_user($data->privatereplyto);
$data->privatereplytofullname = fullname($user, $canviewfullname);
}
// Convert any boolean fields to their integer equivalent for output.
if (is_bool($data->$field)) {
$data->$field = (int) $data->$field;
}
}
if ($striphtml) {
// The following call to html_to_text uses the option that strips out
// all URLs, but format_text complains if it finds @@PLUGINFILE@@ tokens.
@@ -147,12 +170,6 @@ if ($form->is_cancelled()) {
$data->created = userdate($data->created);
$data->modified = userdate($data->modified);
}
foreach ($fields as $field) {
// Convert any boolean fields to their integer equivalent for output.
if (is_bool($data->$field)) {
$data->$field = (int) $data->$field;
}
}
return $data;
});
die;