Skip to content
Snippets Groups Projects
Commit cf5a063e authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Added actions to be able to duplicate workflows

parent cc819aba
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,15 @@ class settings_manager {
global $DB;
self::validate_type($type);
if (!$data) {
return;
}
// Cast data to array.
if (is_object($data)) {
$data = (array) $data;
}
if ($type == SETTINGS_TYPE_TRIGGER) {
$lib = lib_manager::get_trigger_lib($subpluginname);
} else {
......@@ -50,8 +59,8 @@ class settings_manager {
throw new \moodle_exception('id of the step instance has to be set!');
}
foreach ($settingsfields as $setting) {
if (object_property_exists($data, $setting->name)) {
$value = $data->{$setting->name};
if (array_key_exists($setting->name, $data)) {
$value = $data[$setting->name];
// Needed for editor support.
if (is_array($value) && array_key_exists('text', $value)) {
$value = $value['text'];
......
......@@ -181,7 +181,7 @@ class step_manager extends subplugin_manager {
));
$steps = array();
foreach ($records as $id => $record) {
$steps[$id] = $record->instancename;
$steps[$id] = step_subplugin::from_record($record);
}
return $steps;
}
......@@ -287,8 +287,9 @@ class step_manager extends subplugin_manager {
$step->id = null;
$step->workflowid = $newworkflowid;
self::insert_or_update($step);
if ($settings) {
settings_manager::save_settings($step->id, SETTINGS_TYPE_STEP, $step->subpluginname, $settings);
}
}
}
}
......@@ -119,6 +119,9 @@ class workflow_manager {
if ($action === ACTION_DOWN_WORKFLOW) {
self::change_sortindex($workflowid, false);
}
if ($action === ACTION_WORKFLOW_DUPLICATE) {
self::duplicate_workflow($workflowid);
}
if ($action === ACTION_WORKFLOW_DELETE) {
if (self::is_active($workflowid)) {
echo $OUTPUT->notification(get_string('active_workflow_not_removeable', 'tool_cleanupcourses')
......
......@@ -100,6 +100,11 @@ class workflow_definition_table extends \table_sql {
if (!isset($lib) || $lib->has_multiple_instances()) {
$action = ACTION_WORKFLOW_DUPLICATE;
$alt = get_string('duplicateworkflow', 'tool_cleanupcourses');
$icon = 't/copy';
$output .= $this->format_icon_link($action, $row->id, $icon, $alt);
$action = ACTION_WORKFLOW_INSTANCE_FROM;
$alt = get_string('editworkflow', 'tool_cleanupcourses');
$icon = 't/edit';
......
......@@ -65,6 +65,7 @@ $string['workflow_sortindex'] = 'Up/Down';
$string['workflow_tools'] = 'Tools';
$string['viewsteps'] = 'View Workflow Steps';
$string['editworkflow'] = 'Edit Title';
$string['duplicateworkflow'] = 'Duplicate workflow';
$string['deleteworkflow'] = 'Delete Workflow';
$string['activateworkflow'] = 'Activate';
$string['workflow_duplicate_title'] = '{$a} (Copy)';
......
......@@ -38,4 +38,5 @@ define('ACTION_TRIGGER_INSTANCE_FORM', 'trigger_instance_form');
define('ACTION_STEP_INSTANCE_DELETE', 'step_instance_delete');
define('ACTION_WORKFLOW_INSTANCE_FROM', 'workflow_instance_form');
define('ACTION_WORKFLOW_DELETE', 'workflow_instance_delete');
define('ACTION_WORKFLOW_DUPLICATE', 'workflow_instance_duplicate');
define('ACTION_WORKFLOW_ACTIVATE', 'workflow_instance_activate');
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment