MDL-75186 mod_data: Export saved presets
This commit is contained in:
@@ -135,8 +135,9 @@ class presets implements templatable, renderable {
|
||||
$actionmenu->set_action_label(get_string('actions'));
|
||||
$actionmenu->attributes['class'] .= ' presets-actions';
|
||||
|
||||
// Only users with mod/data:manageuserpresets capability have options to edit the preset.
|
||||
if ($preset->can_manage()) {
|
||||
$canmanage = $preset->can_manage();
|
||||
// Edit.
|
||||
if ($canmanage) {
|
||||
$params = [
|
||||
'd' => $this->id,
|
||||
'action' => 'edit',
|
||||
@@ -155,7 +156,23 @@ class presets implements templatable, renderable {
|
||||
$attributes
|
||||
));
|
||||
|
||||
// Delete.
|
||||
}
|
||||
|
||||
// Export.
|
||||
$params = [
|
||||
'd' => $this->id,
|
||||
'presetname' => $preset->name,
|
||||
'action' => 'export',
|
||||
];
|
||||
$exporturl = new moodle_url('/mod/data/preset.php', $params);
|
||||
$actionmenu->add(new action_menu_link_secondary(
|
||||
$exporturl,
|
||||
null,
|
||||
get_string('export', 'mod_data'),
|
||||
));
|
||||
|
||||
// Delete.
|
||||
if ($canmanage) {
|
||||
$params = [
|
||||
'd' => $this->id,
|
||||
'action' => 'delete',
|
||||
|
||||
+4
-1
@@ -86,7 +86,10 @@ if ($action === 'export') {
|
||||
throw new \moodle_exception('headersent');
|
||||
}
|
||||
|
||||
$preset = preset::create_from_instance($manager, $data->name);
|
||||
// Check if we should export a given preset or the current one.
|
||||
$presetname = optional_param('presetname', $data->name, PARAM_FILE);
|
||||
|
||||
$preset = preset::create_from_instance($manager, $presetname);
|
||||
$exportfile = $preset->export();
|
||||
$exportfilename = basename($exportfile);
|
||||
header("Content-Type: application/download\n");
|
||||
|
||||
@@ -260,3 +260,17 @@ Feature: Users can view and manage data presets
|
||||
And I click on "Delete" "button" in the "Delete preset Saved preset by teacher1?" "dialogue"
|
||||
And I should see "Preset deleted"
|
||||
And I should not see "Saved preset by teacher1"
|
||||
|
||||
@javascript
|
||||
Scenario: Teachers can export any saved preset
|
||||
Given I am on the "Mountain landscapes" "data activity" page logged in as teacher1
|
||||
When I follow "Presets"
|
||||
# Plugin presets can't be exported.
|
||||
And I should not see "Actions" in the "Image gallery" "table_row"
|
||||
# The teacher should be able to export any saved preset.
|
||||
And I open the action menu in "Saved preset by teacher1" "table_row"
|
||||
Then I should see "Export"
|
||||
And following "Export" "link" in the "Saved preset by teacher1" "table_row" should download between "1" and "5000" bytes
|
||||
And I open the action menu in "Saved preset 1" "table_row"
|
||||
And I should see "Export"
|
||||
And following "Export" "link" in the "Saved preset 1" "table_row" should download between "1" and "5000" bytes
|
||||
|
||||
Reference in New Issue
Block a user