mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-59470 admin: A user tour can now be duplicated
This commit is contained in:
parent
f622ee97e3
commit
c48fbb6c9b
@ -203,6 +203,21 @@ class helper {
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link used to duplicate the tour.
|
||||
*
|
||||
* @param int $tourid The ID of the tour to duplicate.
|
||||
* @return moodle_url The URL.
|
||||
*/
|
||||
public static function get_duplicate_tour_link($tourid) {
|
||||
$link = new \moodle_url('/admin/tool/usertours/configure.php', [
|
||||
'action' => manager::ACTION_DUPLICATETOUR,
|
||||
'id' => $tourid,
|
||||
]);
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link used to delete the tour.
|
||||
*
|
||||
|
@ -138,6 +138,7 @@ class tour_list extends \flexible_table {
|
||||
|
||||
$actions[] = helper::format_icon_link($tour->get_view_link(), 't/viewdetails', get_string('view'));
|
||||
$actions[] = helper::format_icon_link($tour->get_edit_link(), 't/edit', get_string('edit'));
|
||||
$actions[] = helper::format_icon_link($tour->get_duplicate_link(), 't/copy', get_string('duplicate'));
|
||||
$actions[] = helper::format_icon_link($tour->get_export_link(), 't/export',
|
||||
get_string('exporttour', 'tool_usertours'), 'tool_usertours');
|
||||
$actions[] = helper::format_icon_link($tour->get_delete_link(), 't/delete', get_string('delete'), null, [
|
||||
|
@ -78,6 +78,11 @@ class manager {
|
||||
*/
|
||||
const ACTION_VIEWTOUR = 'viewtour';
|
||||
|
||||
/**
|
||||
* @var ACTION_DUPLICATETOUR The action to duplicate the tour.
|
||||
*/
|
||||
const ACTION_DUPLICATETOUR = 'duplicatetour';
|
||||
|
||||
/**
|
||||
* @var ACTION_NEWSTEP The action to create a new step.
|
||||
*/
|
||||
@ -163,6 +168,10 @@ class manager {
|
||||
$this->view_tour(required_param('id', PARAM_INT));
|
||||
break;
|
||||
|
||||
case self::ACTION_DUPLICATETOUR:
|
||||
$this->duplicate_tour(required_param('id', PARAM_INT));
|
||||
break;
|
||||
|
||||
case self::ACTION_HIDETOUR:
|
||||
$this->hide_tour(required_param('id', PARAM_INT));
|
||||
break;
|
||||
@ -486,6 +495,39 @@ class manager {
|
||||
$this->footer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate an existing tour.
|
||||
*
|
||||
* @param int $tourid The ID of the tour to duplicate.
|
||||
*/
|
||||
protected function duplicate_tour($tourid) {
|
||||
$tour = helper::get_tour($tourid);
|
||||
|
||||
$export = $tour->to_record();
|
||||
// Remove the id.
|
||||
unset($export->id);
|
||||
|
||||
// Set the version.
|
||||
$export->version = get_config('tool_usertours', 'version');
|
||||
|
||||
$export->name = get_string('duplicatetour_name', 'tool_usertours', $export->name);
|
||||
|
||||
// Step export.
|
||||
$export->steps = [];
|
||||
foreach ($tour->get_steps() as $step) {
|
||||
$record = $step->to_record();
|
||||
unset($record->id);
|
||||
unset($record->tourid);
|
||||
|
||||
$export->steps[] = $record;
|
||||
}
|
||||
|
||||
$exportstring = json_encode($export);
|
||||
$newtour = self::import_tour_from_json($exportstring);
|
||||
|
||||
redirect($newtour->get_view_link());
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the tour.
|
||||
*
|
||||
|
@ -356,6 +356,15 @@ class tour {
|
||||
return helper::get_export_tour_link($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The link to duplicate this tour.
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_duplicate_link() {
|
||||
return helper::get_duplicate_tour_link($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The link to remove this tour.
|
||||
*
|
||||
|
@ -44,6 +44,8 @@ $string['cssselector'] = 'CSS selector';
|
||||
$string['defaultvalue'] = 'Default ({$a})';
|
||||
$string['delay'] = 'Delay before showing the step';
|
||||
$string['done'] = 'Done';
|
||||
$string['duplicatetour'] = 'Duplicate tour';
|
||||
$string['duplicatetour_name'] = '{$a} (copy)';
|
||||
$string['editstep'] = 'Editing "{$a}"';
|
||||
$string['tourisenabled'] = 'Tour is enabled';
|
||||
$string['enabled'] = 'Enabled';
|
||||
|
Loading…
x
Reference in New Issue
Block a user