MDL-57455 mod_data: Import and export tags

This commit is contained in:
Andrew Hancox
2017-10-12 16:59:15 +08:00
committed by Mark Nelson
parent d45c7a6823
commit 04f7b079bc
5 changed files with 34 additions and 3 deletions
+2 -1
View File
@@ -32,6 +32,7 @@ $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
$tags = optional_param('exporttags', false, PARAM_BOOL); // Flag for exporting user details.
$PAGE->set_url('/mod/data/export.php', array('d'=>$d));
@@ -111,7 +112,7 @@ foreach ($formdata as $key => $value) {
$currentgroup = groups_get_activity_group($cm);
$exportdata = data_get_exportdata($data->id, $fields, $selectedfields, $currentgroup, $context,
$exportuser, $exporttime, $exportapproval);
$exportuser, $exporttime, $exportapproval, $tags);
$count = count($exportdata);
switch ($formdata['exporttype']) {
case 'csv':
+5
View File
@@ -85,6 +85,11 @@ class mod_data_export_form extends moodleform {
if ($this->_data->approval) {
$mform->addElement('checkbox', 'exportapproval', get_string('includeapproval', 'data'));
}
if (core_tag_tag::is_enabled('mod_data', 'data_records')) {
$mform->addElement('checkbox', 'exporttags', get_string('includetags', 'data'));
}
$this->add_action_buttons(true, get_string('exportentries', 'data'));
}
+16 -1
View File
@@ -116,7 +116,7 @@ if (!$formdata = $form->get_data()) {
$errorfield = '';
$safetoskipfields = array(get_string('user'), get_string('username'), get_string('email'),
get_string('timeadded', 'data'), get_string('timemodified', 'data'),
get_string('approved', 'data'));
get_string('approved', 'data'), get_string('tags', 'data'));
foreach ($fieldnames as $name => $id) {
if (!isset($rawfields[$name])) {
if (!in_array($name, $safetoskipfields)) {
@@ -156,6 +156,21 @@ if (!$formdata = $form->get_data()) {
$DB->insert_record('data_content', $content);
}
}
if (core_tag_tag::is_enabled('mod_data', 'data_records') &&
isset($fieldnames[get_string('tags', 'data')])) {
$columnindex = $fieldnames[get_string('tags', 'data')];
$rawtags = $record[$columnindex];
$tags = explode(',', $rawtags);
foreach ($tags as $tag) {
$tag = trim($tag);
if (empty($tag)) {
continue;
}
core_tag_tag::add_item_tag('mod_data', 'data_records', $recordid, $context, $tag);
}
}
$recordsadded++;
print get_string('added', 'moodle', $recordsadded) . ". " . get_string('entry', 'data') . " (ID $recordid)<br />\n";
}
+2
View File
@@ -201,6 +201,7 @@ $string['expired'] = 'Sorry, this activity closed on {$a} and is no longer avail
$string['importentries'] = 'Import entries';
$string['importsuccess'] = 'The preset has been successfully applied.';
$string['includeapproval'] = 'Include approval status';
$string['includetags'] = 'Include tags';
$string['includetime'] = 'Include time added/modified';
$string['includeuserdetails'] = 'Include user details';
$string['indicator:cognitivedepth'] = 'Database cognitive';
@@ -346,6 +347,7 @@ $string['subplugintype_datafield_plural'] = 'Database field types';
$string['subplugintype_datapreset'] = 'Preset';
$string['subplugintype_datapreset_plural'] = 'Presets';
$string['tagarea_data_records'] = 'Data records';
$string['tags'] = 'tags';
$string['teachersandstudents'] = '{$a->teachers} and {$a->students}';
$string['templates'] = 'Templates';
$string['templatesaved'] = 'Template saved';
+9 -1
View File
@@ -3103,10 +3103,11 @@ function data_export_ods($export, $dataname, $count) {
* @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
* @param bool $tags whether to include tags
* @return array
*/
function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0, $context=null,
$userdetails=false, $time=false, $approval=false) {
$userdetails=false, $time=false, $approval=false, $tags = false) {
global $DB;
if (is_null($context)) {
@@ -3138,6 +3139,9 @@ function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0,
if ($approval) {
$exportdata[0][] = get_string('approved', 'data');
}
if ($tags) {
$exportdata[0][] = get_string('tags', 'data');
}
$datarecords = $DB->get_records('data_records', array('dataid'=>$dataid));
ksort($datarecords);
@@ -3173,6 +3177,10 @@ function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0,
if ($approval) { // Add approval status
$exportdata[$line][] = (int) $record->approved;
}
if ($tags) {
$itemtags = \core_tag_tag::get_item_tags_array('mod_data', 'data_records', $record->id);
$exportdata[$line][] = implode(', ', $itemtags);
}
}
$line++;
}