Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-22773 Database module export: include internal fields

Fields included:
 * User details (fullname, username, email)
 * Time added/modified
 * Approval status
  • Loading branch information...
commit 4f304eeb3dc62482bd7e931875b4820e3a6b27a5 1 parent 470d47f
@bostelm bostelm authored
View
13 mod/data/db/access.php
@@ -237,6 +237,19 @@
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
+ ),
+
+ 'mod/data:exportuserinfo' => array(
+
+ 'riskbitmask' => RISK_PERSONAL,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'archetypes' => array(
+ 'manager' => CAP_ALLOW,
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ )
),
);
View
8 mod/data/export.php
@@ -29,6 +29,9 @@
// database ID
$d = required_param('d', PARAM_INT);
+$exportuser = optional_param('exportuser', false, PARAM_BOOL); // Flag for exporting user details
+$exporttime = optional_param('exporttime', false, PARAM_BOOL); // Flag for exporting date/time information
+$exportapproval = optional_param('exportapproval', false, PARAM_BOOL); // Flag for exporting user details
$PAGE->set_url('/mod/data/export.php', array('d'=>$d));
@@ -72,7 +75,7 @@
}
-$mform = new mod_data_export_form('export.php?d='.$data->id, $fields, $cm);
+$mform = new mod_data_export_form('export.php?d='.$data->id, $fields, $cm, $data);
if($mform->is_cancelled()) {
redirect('view.php?d='.$data->id);
@@ -105,7 +108,8 @@
$currentgroup = groups_get_activity_group($cm);
-$exportdata = data_get_exportdata($data->id, $fields, $selectedfields, $currentgroup);
+$exportdata = data_get_exportdata($data->id, $fields, $selectedfields, $currentgroup, $context,
+ $exportuser, $exporttime, $exportapproval);
$count = count($exportdata);
switch ($formdata['exporttype']) {
case 'csv':
View
12 mod/data/export_form.php
@@ -9,12 +9,14 @@
class mod_data_export_form extends moodleform {
var $_datafields = array();
var $_cm;
+ var $_data;
// @param string $url: the url to post to
// @param array $datafields: objects in this database
- function mod_data_export_form($url, $datafields, $cm) {
+ function mod_data_export_form($url, $datafields, $cm, $data) {
$this->_datafields = $datafields;
$this->_cm = $cm;
+ $this->_data = $data;
parent::moodleform($url);
}
@@ -56,6 +58,14 @@ function definition() {
}
}
$this->add_checkbox_controller(1, null, null, 1);
+ $context = context_module::instance($this->_cm->id);
+ if (has_capability('mod/data:exportuserinfo', $context)) {
+ $mform->addElement('checkbox', 'exportuser', get_string('includeuserdetails', 'data'));
+ }
+ $mform->addElement('checkbox', 'exporttime', get_string('includetime', 'data'));
+ if ($this->_data->approval) {
+ $mform->addElement('checkbox', 'exportapproval', get_string('includeapproval', 'data'));
+ }
$this->add_action_buttons(true, get_string('exportentries', 'data'));
}
View
4 mod/data/lang/en/data.php
@@ -80,6 +80,7 @@
$string['data:exportallentries'] = 'Export all database entries';
$string['data:exportentry'] = 'Export a database entry';
$string['data:exportownentry'] = 'Export own database entry';
+$string['data:exportuserinfo'] = 'Export user information';
$string['data:managecomments'] = 'Manage comments';
$string['data:manageentries'] = 'Manage entries';
$string['data:managetemplates'] = 'Manage templates';
@@ -177,6 +178,9 @@
$string['expired'] = 'Sorry, this activity closed on {$a} and is no longer available';
$string['importentries'] = 'Import entries';
$string['importsuccess'] = 'The preset has been successfully applied.';
+$string['includeapproval'] = 'Include approval status';
+$string['includetime'] = 'Include time added/modified';
+$string['includeuserdetails'] = 'Include user details';
$string['insufficiententries'] = 'more entries needed to view this database';
$string['intro'] = 'Introduction';
$string['invalidaccess'] = 'This page was not accessed correctly';
View
38 mod/data/lib.php
@@ -2755,11 +2755,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
@@ -2771,6 +2782,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);
@@ -2793,6 +2816,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++;
}
View
2  mod/data/version.php
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
-$module->version = 2012061700; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2012061701; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012061700; // Requires this Moodle version
$module->component = 'mod_data'; // Full name of the plugin (used for diagnostics)
$module->cron = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.