mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-22773' of git://github.com/bostelm/moodle
This commit is contained in:
commit
dbf2c5bfef
@ -230,6 +230,19 @@ $capabilities = array(
|
||||
|
||||
'riskbitmask' => RISK_PERSONAL,
|
||||
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'manager' => CAP_ALLOW,
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
)
|
||||
),
|
||||
|
||||
'mod/data:exportuserinfo' => array(
|
||||
|
||||
'riskbitmask' => RISK_PERSONAL,
|
||||
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
|
@ -29,6 +29,9 @@ require_once('export_form.php');
|
||||
|
||||
// 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 @@ foreach ($fieldrecords as $fieldrecord) {
|
||||
}
|
||||
|
||||
|
||||
$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 @@ foreach ($formdata as $key => $value) {
|
||||
|
||||
$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':
|
||||
|
@ -9,12 +9,14 @@ require_once($CFG->libdir . '/csvlib.class.php');
|
||||
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 @@ class mod_data_export_form extends moodleform {
|
||||
}
|
||||
}
|
||||
$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'));
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,7 @@ $string['data:comment'] = 'Write comments';
|
||||
$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['chooseorupload'] = 'Choose file';
|
||||
$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';
|
||||
|
@ -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++;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user