Merge branch 'MDL-22773' of git://github.com/bostelm/moodle
This commit is contained in:
+37
-1
@@ -2737,11 +2737,22 @@ function data_export_ods($export, $dataname, $count) {
|
||||
* @param array $selectedfields
|
||||
* @param int $currentgroup group ID of the current group. This is used for
|
||||
* exporting data while maintaining group divisions.
|
||||
* @param object $context the context in which the operation is performed (for capability checks)
|
||||
* @param bool $userdetails whether to include the details of the record author
|
||||
* @param bool $time whether to include time created/modified
|
||||
* @param bool $approval whether to include approval status
|
||||
* @return array
|
||||
*/
|
||||
function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0) {
|
||||
function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0, $context=null,
|
||||
$userdetails=false, $time=false, $approval=false) {
|
||||
global $DB;
|
||||
|
||||
if (is_null($context)) {
|
||||
$context = context_system::instance();
|
||||
}
|
||||
// exporting user data needs special permission
|
||||
$userdetails = $userdetails && has_capability('mod/data:exportuserinfo', $context);
|
||||
|
||||
$exportdata = array();
|
||||
|
||||
// populate the header in first row of export
|
||||
@@ -2753,6 +2764,18 @@ function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0)
|
||||
$exportdata[0][] = $field->field->name;
|
||||
}
|
||||
}
|
||||
if ($userdetails) {
|
||||
$exportdata[0][] = get_string('user');
|
||||
$exportdata[0][] = get_string('username');
|
||||
$exportdata[0][] = get_string('email');
|
||||
}
|
||||
if ($time) {
|
||||
$exportdata[0][] = get_string('timeadded', 'data');
|
||||
$exportdata[0][] = get_string('timemodified', 'data');
|
||||
}
|
||||
if ($approval) {
|
||||
$exportdata[0][] = get_string('approved', 'data');
|
||||
}
|
||||
|
||||
$datarecords = $DB->get_records('data_records', array('dataid'=>$dataid));
|
||||
ksort($datarecords);
|
||||
@@ -2775,6 +2798,19 @@ function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0)
|
||||
}
|
||||
$exportdata[$line][] = $contents;
|
||||
}
|
||||
if ($userdetails) { // Add user details to the export data
|
||||
$userdata = get_complete_user_data('id', $record->userid);
|
||||
$exportdata[$line][] = fullname($userdata);
|
||||
$exportdata[$line][] = $userdata->username;
|
||||
$exportdata[$line][] = $userdata->email;
|
||||
}
|
||||
if ($time) { // Add time added / modified
|
||||
$exportdata[$line][] = userdate($record->timecreated);
|
||||
$exportdata[$line][] = userdate($record->timemodified);
|
||||
}
|
||||
if ($approval) { // Add approval status
|
||||
$exportdata[$line][] = (int) $record->approved;
|
||||
}
|
||||
}
|
||||
$line++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user