Skip to content

Commit

Permalink
MDL-67846 mod_forum: export user full name
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Feb 25, 2020
1 parent 37b2ee3 commit 041ff27
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions mod/forum/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@
$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));
Expand All @@ -132,8 +134,29 @@
$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.
Expand All @@ -147,12 +170,6 @@ function($exportdata) use ($fields, $striphtml, $humandates) {
$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;
Expand Down

0 comments on commit 041ff27

Please sign in to comment.