Skip to content

Commit

Permalink
Merge branch 'MDL-69422-master-2' of git://github.com/junpataleta/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Dec 22, 2020
2 parents cc1ad82 + 15709f1 commit b2382c7
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lib/form/templates/element-advcheckbox.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
{{{label}}}
{{/text}}
</label>
<span class="ml-2 d-flex align-items-center align-self-start">
<div class="ml-2 d-flex align-items-center align-self-start">
{{#required}}
<div class="text-danger" title="{{#str}}required{{/str}}">
{{#pix}}req, core, {{#str}}required{{/str}}{{/pix}}
</div>
{{/required}}
{{{helpbutton}}}
</span>
</div>
</div>
<div class="form-control-feedback invalid-feedback" id="{{element.iderror}}" {{#error}} style="display: block;"{{/error}}>
{{{error}}}
Expand Down
4 changes: 2 additions & 2 deletions lib/form/templates/element-checkbox.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
{{{label}}}
{{/text}}
</label>
<span class="ml-2 d-flex align-items-center align-self-start">
<div class="ml-2 d-flex align-items-center align-self-start">
{{#required}}
<div class="text-danger" title="{{#str}}required{{/str}}">
{{#pix}}req, core, {{#str}}required{{/str}}{{/pix}}
</div>
{{/required}}
{{{helpbutton}}}
</span>
</div>
</div>
<div class="form-control-feedback invalid-feedback" id="{{element.iderror}}" {{#error}} style="display: block;"{{/error}}>
{{{error}}}
Expand Down
4 changes: 2 additions & 2 deletions lib/form/templates/element-radio.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
{{{label}}}
{{/text}}
</label>
<span class="ml-2 d-flex align-items-center align-self-start">
<div class="ml-2 d-flex align-items-center align-self-start">
{{#required}}
<div class="text-danger" title="{{#str}}required{{/str}}">
{{#pix}}req, core, {{#str}}required{{/str}}{{/pix}}
</div>
{{/required}}
{{{helpbutton}}}
</span>
</div>
</div>
<div class="form-control-feedback invalid-feedback" id="{{element.iderror}}" {{#error}} style="display: block;"{{/error}}>
{{{error}}}
Expand Down
4 changes: 2 additions & 2 deletions lib/form/templates/element-template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
</span>
{{/element.staticlabel}}
{{/ label }}{{/ label}}
<span class="ml-1 ml-md-auto d-flex align-items-center align-self-start">
<div class="ml-1 ml-md-auto d-flex align-items-center align-self-start">
{{#required}}
<div class="text-danger" title="{{#str}}required{{/str}}">
{{#pix}}req, core, {{#str}}required{{/str}}{{/pix}}
</div>
{{/required}}
{{{helpbutton}}}
</span>
</div>
</div>
<div class="col-md-9 form-inline align-items-start felement" data-fieldtype="{{element.type}}">
{{$ element }}
Expand Down
82 changes: 53 additions & 29 deletions mod/data/export_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,64 +31,88 @@ public function mod_data_export_form($url, $datafields, $cm, $data) {
}

function definition() {
global $CFG;
$mform =& $this->_form;
$mform->addElement('header', 'notice', get_string('chooseexportformat', 'data'));
$choices = csv_import_reader::get_delimiter_list();
$key = array_search(';', $choices);
if (! $key === FALSE) {
// array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon):
unset($choices[$key]);
}
$mform->addElement('header', 'exportformat', get_string('chooseexportformat', 'data'));

$optionattrs = ['class' => 'mt-1 mb-1'];

// Export format type radio group.
$typesarray = array();
$str = get_string('csvwithselecteddelimiter', 'data');
$typesarray[] = $mform->createElement('radio', 'exporttype', null, $str . '&nbsp;', 'csv');
$typesarray[] = $mform->createElement('select', 'delimiter_name', null, $choices);
//temporarily commenting out Excel export option. See MDL-19864
$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data'), 'csv',
$optionattrs);
// Temporarily commenting out Excel export option. See MDL-19864.
//$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls');
$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods');
$mform->addGroup($typesarray, 'exportar', '', array(''), false);
$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods', $optionattrs);
$mform->addGroup($typesarray, 'exportar', get_string('exportformat', 'data'), null, false);
$mform->addRule('exportar', null, 'required');
$mform->setDefault('exporttype', 'csv');

// CSV delimiter list.
$choices = csv_import_reader::get_delimiter_list();
$key = array_search(';', $choices);
if ($key !== false) {
// Array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon):
unset($choices[$key]);
}
$mform->addElement('select', 'delimiter_name', get_string('fielddelimiter', 'data'), $choices);
$mform->hideIf('delimiter_name', 'exporttype', 'neq', 'csv');
if (array_key_exists('cfg', $choices)) {
$mform->setDefault('delimiter_name', 'cfg');
} else if (get_string('listsep', 'langconfig') == ';') {
$mform->setDefault('delimiter_name', 'semicolon');
} else {
$mform->setDefault('delimiter_name', 'comma');
}
$mform->addElement('header', 'notice', get_string('chooseexportfields', 'data'));

// Fields to be exported.
$mform->addElement('header', 'exportfieldsheader', get_string('chooseexportfields', 'data'));
$mform->setExpanded('exportfieldsheader');
$numfieldsthatcanbeselected = 0;
foreach($this->_datafields as $field) {
if($field->text_export_supported()) {
$exportfields = [];
$unsupportedfields = [];
foreach ($this->_datafields as $field) {
$label = get_string('fieldnametype', 'data', (object)['name' => $field->field->name, 'type' => $field->name()]);
if ($field->text_export_supported()) {
$numfieldsthatcanbeselected++;
$html = '<div title="' . s($field->field->description) . '" ' .
'class="d-inline-block">' . $field->field->name . '</div>';
$name = ' (' . $field->name() . ')';
$mform->addElement('advcheckbox', 'field_' . $field->field->id, $html, $name, array('group' => 1));
$exportfields[] = $mform->createElement('advcheckbox', 'field_' . $field->field->id, '', $label,
array_merge(['group' => 1], $optionattrs));
$mform->setDefault('field_' . $field->field->id, 1);
} else {
$a = new stdClass();
$a->fieldtype = $field->name();
$str = get_string('unsupportedexport', 'data', $a);
$mform->addElement('static', 'unsupported' . $field->field->id, $field->field->name, $str);
$unsupportedfields[] = $label;
}
}
$mform->addGroup($exportfields, 'exportfields', get_string('selectfields', 'data'), ['<br>'], false);

if ($numfieldsthatcanbeselected > 1) {
$this->add_checkbox_controller(1, null, null, 1);
}

// List fields that cannot be exported.
if (!empty($unsupportedfields)) {
$unsupportedfieldslist = html_writer::tag('p', get_string('unsupportedfieldslist', 'data'), ['class' => 'mt-1']);
$unsupportedfieldslist .= html_writer::alist($unsupportedfields);
$mform->addElement('static', 'unsupportedfields', get_string('unsupportedfields', 'data'), $unsupportedfieldslist);
}

// Export options.
$mform->addElement('header', 'exportoptionsheader', get_string('exportoptions', 'data'));
$mform->setExpanded('exportoptionsheader');
$exportoptions = [];
if (core_tag_tag::is_enabled('mod_data', 'data_records')) {
$mform->addElement('checkbox', 'exporttags', get_string('includetags', 'data'));
$exportoptions[] = $mform->createElement('checkbox', 'exporttags', get_string('includetags', 'data'), '', $optionattrs);
$mform->setDefault('exporttags', 1);
}
$context = context_module::instance($this->_cm->id);
if (has_capability('mod/data:exportuserinfo', $context)) {
$mform->addElement('checkbox', 'exportuser', get_string('includeuserdetails', 'data'));
$exportoptions[] = $mform->createElement('checkbox', 'exportuser', get_string('includeuserdetails', 'data'), '',
$optionattrs);
}
$mform->addElement('checkbox', 'exporttime', get_string('includetime', 'data'));
$exportoptions[] = $mform->createElement('checkbox', 'exporttime', get_string('includetime', 'data'), '', $optionattrs);
if ($this->_data->approval) {
$mform->addElement('checkbox', 'exportapproval', get_string('includeapproval', 'data'));
$exportoptions[] = $mform->createElement('checkbox', 'exportapproval', get_string('includeapproval', 'data'), '',
$optionattrs);
}
$mform->addGroup($exportoptions, 'exportoptions', get_string('selectexportoptions', 'data'), ['<br>'], false);

$this->add_action_buttons(true, get_string('exportentries', 'data'));
}
Expand Down
19 changes: 14 additions & 5 deletions mod/data/lang/en/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
$string['csvfile'] = 'CSV file';
$string['csvimport'] = 'CSV file import';
$string['csvimport_help'] = 'Entries may be imported via a plain text file with a list of field names as the first line, then the data, with one record per line.';
$string['csvwithselecteddelimiter'] = '<acronym title="Comma Separated Values">CSV</acronym> text with selected delimiter:';
$string['csvwithselecteddelimiter'] = '<abbr title="Comma Separated Values">CSV</abbr>';
$string['data:addinstance'] = 'Add a new database';
$string['data:approve'] = 'Approve and undo approved entries';
$string['data:comment'] = 'Write comments';
Expand Down Expand Up @@ -153,6 +153,8 @@
$string['exportaszip_help'] = 'The export as zip feature allows you to save the templates and fields as a preset zip for download. The zip may then be imported to another course.';
$string['exportedtozip'] = 'Exported to temporary zip...';
$string['exportentries'] = 'Export entries';
$string['exportformat'] = 'Export format';
$string['exportoptions'] = 'Export options';
$string['exportownentries'] = 'Export your own entries only? ({$a->mine}/{$a->all})';
$string['failedpresetdelete'] = 'Error deleting a preset!';
$string['fieldadded'] = 'Field added';
Expand All @@ -169,6 +171,7 @@
$string['fieldmappings_help'] = 'This menu allows you to keep the data from the existing database. To preserve the data in a field, you must map it to a new field, where the data will appear. Any field can also be left blank, with no information copied into it. Any old field not mapped to a new one will be lost and all its data removed.
You can only map fields of the same type, so each drop-down menu will have different fields in it. Also, you must be careful not to try and map one old field to more than one new field.';
$string['fieldname'] = 'Field name';
$string['fieldnametype'] = '{$a->name} ({$a->type})';
$string['fieldnotmatched'] = 'The following fields in your file are not known in this database: {$a}';
$string['fieldoptions'] = 'Options (one per line)';
$string['fields'] = 'Fields';
Expand All @@ -195,8 +198,8 @@
$string['headerrsstemplate'] = 'Defines appearance of entries in RSS feeds';
$string['headersingletemplate'] = 'Defines browsing interface for a single entry';
$string['checkbox'] = 'Checkbox';
$string['chooseexportfields'] = 'Choose the fields you wish to export:';
$string['chooseexportformat'] = 'Choose the format you wish to export to:';
$string['chooseexportfields'] = 'Choose the fields you wish to export';
$string['chooseexportformat'] = 'Choose the format you wish to export to';
$string['chooseorupload'] = 'Choose file';
$string['expired'] = 'Sorry, this activity closed on {$a} and is no longer available';
$string['importentries'] = 'Import entries';
Expand Down Expand Up @@ -290,7 +293,7 @@
$string['numberrssarticles'] = 'Entries in the RSS feed';
$string['numnotapproved'] = 'Pending';
$string['numrecords'] = '{$a} entries';
$string['ods'] = '<acronym title="OpenDocument Spreadsheet">ODS</acronym> (OpenOffice)';
$string['ods'] = '<abbr title="OpenDocument Spreadsheet">ODS</abbr>&nbsp;(OpenOffice)';
$string['openafterclose'] = 'You have specified an open date after the close date';
$string['optionaldescription'] = 'Short description (optional)';
$string['optionalfilename'] = 'Filename (optional)';
Expand Down Expand Up @@ -366,6 +369,8 @@
$string['search:activity'] = 'Database - activity information';
$string['search:entry'] = 'Database - entries';
$string['selectedrequired'] = 'All selected required';
$string['selectfields'] = 'Select fields';
$string['selectexportoptions'] = 'Select export options';
$string['showall'] = 'Show all entries';
$string['single'] = 'View single';
$string['singletemplate'] = 'Single template';
Expand All @@ -386,7 +391,8 @@
$string['todatabase'] = 'to this database.';
$string['type'] = 'Field type';
$string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action "{$a}".';
$string['unsupportedexport'] = '({$a->fieldtype}) cannot be exported.';
$string['unsupportedfields'] = 'Unsupported fields';
$string['unsupportedfieldslist'] = 'The following fields cannot be exported:';
$string['updatefield'] = 'Update an existing field';
$string['uploadfile'] = 'Upload file';
$string['uploadrecords'] = 'Upload entries from a file';
Expand All @@ -406,3 +412,6 @@
$string['viewtodate'] = 'Read only to';
$string['viewtodatevalidation'] = 'The read only to date cannot be before the read only from date.';
$string['wrongdataid'] = 'Wrong data id provided';

// Deprecated since Moodle 3.11.
$string['unsupportedexport'] = '({$a->fieldtype}) cannot be exported.';
1 change: 1 addition & 0 deletions mod/data/lang/en/deprecated.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unsupportedexport,mod_data

0 comments on commit b2382c7

Please sign in to comment.