diff --git a/mod/data/export.php b/mod/data/export.php index 2ac6bb6ee0271..b2444f35ebd21 100644 --- a/mod/data/export.php +++ b/mod/data/export.php @@ -32,6 +32,7 @@ $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 @@ $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': diff --git a/mod/data/export_form.php b/mod/data/export_form.php index fdee10f0a3e5d..d100e8c4e58e0 100644 --- a/mod/data/export_form.php +++ b/mod/data/export_form.php @@ -85,6 +85,11 @@ function definition() { 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')); } diff --git a/mod/data/import.php b/mod/data/import.php index 03f48156ca184..c2c0c376dde68 100644 --- a/mod/data/import.php +++ b/mod/data/import.php @@ -116,7 +116,7 @@ $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 @@ $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)
\n"; } diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index 35334421aa897..2f52df11e8a4b 100644 --- a/mod/data/lang/en/data.php +++ b/mod/data/lang/en/data.php @@ -201,6 +201,7 @@ $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_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'; diff --git a/mod/data/lib.php b/mod/data/lib.php index 54e247c98b6b6..9875d39392060 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -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++; }