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

Restructured execute function to reduce cyclomatic complexity

parent 740fc1e0
No related branches found
No related tags found
No related merge requests found
...@@ -365,10 +365,46 @@ class workflow_settings { ...@@ -365,10 +365,46 @@ class workflow_settings {
* This is the entry point for this controller class. * This is the entry point for this controller class.
*/ */
public function execute($action, $subplugin) { public function execute($action, $subplugin) {
global $PAGE, $OUTPUT; global $PAGE;
$this->check_permissions(); $this->check_permissions();
if ($action === ACTION_TRIGGER_INSTANCE_FORM) { if ($action === ACTION_TRIGGER_INSTANCE_FORM) {
if ($this->handle_trigger_instance_form()) {
return;
}
}
// If trigger is not yet set, redirect to trigger form!
$trigger = trigger_manager::get_trigger_for_workflow($this->workflowid);
if ($trigger === null) {
$subpluginname = null;
if ($name = optional_param('subpluginname', null, PARAM_ALPHA)) {
$subpluginname = $name;
}
$triggerform = new form_trigger_instance($PAGE->url, $this->workflowid, null, $subpluginname);
$this->view_trigger_instance_form($triggerform);
return;
}
// Handle other actions.
step_manager::handle_action($action, $subplugin);
workflow_manager::handle_action($action, $subplugin);
if ($action === ACTION_STEP_INSTANCE_FORM) {
if ($this->handle_step_instance_form()) {
return;
}
}
// If no action handler has printed any form yet, display the plugins tables.
$this->view_plugins_table();
}
/**
* Handles actions for the trigger instance form and causes related forms to be rendered.
* @return bool True, if no further action handling or output should be conducted.
*/
private function handle_trigger_instance_form() {
global $OUTPUT, $PAGE;
$subpluginname = null; $subpluginname = null;
$settings = null; $settings = null;
if ($trigger = trigger_manager::get_trigger_for_workflow($this->workflowid)) { if ($trigger = trigger_manager::get_trigger_for_workflow($this->workflowid)) {
...@@ -399,31 +435,21 @@ class workflow_settings { ...@@ -399,31 +435,21 @@ class workflow_settings {
// Save local subplugin settings. // Save local subplugin settings.
settings_manager::save_settings($trigger->id, SETTINGS_TYPE_TRIGGER, $data->subpluginname, $data); settings_manager::save_settings($trigger->id, SETTINGS_TYPE_TRIGGER, $data->subpluginname, $data);
} }
$this->view_plugins_table(); return false;
return;
} else { } else {
$this->view_trigger_instance_form($form); $this->view_trigger_instance_form($form);
return; return true;
}
} }
} }
return false;
// If trigger is not yet set, redirect to trigger form!
$trigger = trigger_manager::get_trigger_for_workflow($this->workflowid);
if ($trigger === null) {
$subpluginname = null;
if ($name = optional_param('subpluginname', null, PARAM_ALPHA)) {
$subpluginname = $name;
}
$triggerform = new form_trigger_instance($PAGE->url, $this->workflowid, null, $subpluginname);
$this->view_trigger_instance_form($triggerform);
return;
} }
step_manager::handle_action($action, $subplugin); /**
workflow_manager::handle_action($action, $subplugin); * Handles actions for the trigger instance form and causes related forms to be rendered.
* @return bool True, if no further action handling or output should be conducted.
if ($action === ACTION_STEP_INSTANCE_FORM) { */
private function handle_step_instance_form() {
global $OUTPUT, $PAGE;
$steptomodify = null; $steptomodify = null;
$subpluginname = null; $subpluginname = null;
$stepsettings = null; $stepsettings = null;
...@@ -431,22 +457,19 @@ class workflow_settings { ...@@ -431,22 +457,19 @@ class workflow_settings {
$steptomodify = step_manager::get_step_instance($stepid); $steptomodify = step_manager::get_step_instance($stepid);
// If step was removed! // If step was removed!
if (!$steptomodify) { if (!$steptomodify) {
$this->view_plugins_table(); return false;
return;
} }
$stepsettings = settings_manager::get_settings($stepid, SETTINGS_TYPE_STEP); $stepsettings = settings_manager::get_settings($stepid, SETTINGS_TYPE_STEP);
} else if ($name = optional_param('subpluginname', null, PARAM_ALPHA)) { } else if ($name = optional_param('subpluginname', null, PARAM_ALPHA)) {
$subpluginname = $name; $subpluginname = $name;
} else { } else {
$this->view_plugins_table(); return false;
return;
} }
$form = new form_step_instance($PAGE->url, $steptomodify, $this->workflowid, $subpluginname, $stepsettings); $form = new form_step_instance($PAGE->url, $steptomodify, $this->workflowid, $subpluginname, $stepsettings);
if ($form->is_cancelled()) { if ($form->is_cancelled()) {
$this->view_plugins_table(); return false;
return;
} else if ($form->is_submitted() && $form->is_validated() && $data = $form->get_submitted_data()) { } else if ($form->is_submitted() && $form->is_validated() && $data = $form->get_submitted_data()) {
// In case the workflow is active, we do not allow changes to the steps or trigger. // In case the workflow is active, we do not allow changes to the steps or trigger.
if (workflow_manager::is_active($this->workflowid)) { if (workflow_manager::is_active($this->workflowid)) {
...@@ -464,14 +487,12 @@ class workflow_settings { ...@@ -464,14 +487,12 @@ class workflow_settings {
// Save local subplugin settings. // Save local subplugin settings.
settings_manager::save_settings($step->id, SETTINGS_TYPE_STEP, $form->subpluginname, $data); settings_manager::save_settings($step->id, SETTINGS_TYPE_STEP, $form->subpluginname, $data);
} }
$this->view_plugins_table();
return;
} else { } else {
$this->view_step_instance_form($form); $this->view_step_instance_form($form);
return; return true;
}
} }
$this->view_plugins_table(); return false;
} }
} }
\ 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