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

Form_step_instance can now save step settings

parent 495de068
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ namespace tool_cleanupcourses; ...@@ -18,6 +18,7 @@ namespace tool_cleanupcourses;
use tool_cleanupcourses\manager\step_manager; use tool_cleanupcourses\manager\step_manager;
use tool_cleanupcourses\manager\trigger_manager; use tool_cleanupcourses\manager\trigger_manager;
use tool_cleanupcourses\manager\settings_manager;
use tool_cleanupcourses\entity\step_subplugin; use tool_cleanupcourses\entity\step_subplugin;
use tool_cleanupcourses\table\step_table; use tool_cleanupcourses\table\step_table;
use tool_cleanupcourses\table\trigger_table; use tool_cleanupcourses\table\trigger_table;
...@@ -182,6 +183,9 @@ class subplugin_settings { ...@@ -182,6 +183,9 @@ class subplugin_settings {
$steptomodify = $stepmanager->get_subplugin_by_id($stepid); $steptomodify = $stepmanager->get_subplugin_by_id($stepid);
} elseif ($name = optional_param('subpluginname', null, PARAM_ALPHA)) { } elseif ($name = optional_param('subpluginname', null, PARAM_ALPHA)) {
$subpluginname = $name; $subpluginname = $name;
} else {
$this->view_plugins_table();
return;
} }
$form = new form_step_instance($PAGE->url, $steptomodify, $subpluginname); $form = new form_step_instance($PAGE->url, $steptomodify, $subpluginname);
...@@ -189,9 +193,12 @@ class subplugin_settings { ...@@ -189,9 +193,12 @@ class subplugin_settings {
if ($action === ACTION_STEP_INSTANCE_FORM) { if ($action === ACTION_STEP_INSTANCE_FORM) {
$this->view_step_instance_form($form); $this->view_step_instance_form($form);
} else { } else {
if ($form->is_submitted() && !$form->is_cancelled()) { if ($form->is_submitted() && !$form->is_cancelled() && $data = $form->get_submitted_data()) {
$step = step_subplugin::from_record($form->get_submitted_data()); $step = step_subplugin::from_record($data);
$stepmanager->insert_or_update($step); $stepmanager->insert_or_update($step);
// Save local subplugin settings.
$settingsmanager = new settings_manager();
$settingsmanager->save_settings($form->subpluginname, $data);
} }
$this->view_plugins_table(); $this->view_plugins_table();
} }
......
...@@ -59,7 +59,6 @@ class form_step_instance extends \moodleform { ...@@ -59,7 +59,6 @@ class form_step_instance extends \moodleform {
* @param step_subplugin $step * @param step_subplugin $step
*/ */
public function __construct($url, $step, $subpluginname = null) { public function __construct($url, $step, $subpluginname = null) {
parent::__construct($url);
$this->step = $step; $this->step = $step;
if ($step) { if ($step) {
$this->subpluginname = $step->subpluginname; $this->subpluginname = $step->subpluginname;
...@@ -70,6 +69,8 @@ class form_step_instance extends \moodleform { ...@@ -70,6 +69,8 @@ class form_step_instance extends \moodleform {
} }
$libmanager = new lib_manager(); $libmanager = new lib_manager();
$this->lib = $libmanager->get_step_lib($this->subpluginname); $this->lib = $libmanager->get_step_lib($this->subpluginname);
parent::__construct($url);
} }
/** /**
...@@ -81,6 +82,8 @@ class form_step_instance extends \moodleform { ...@@ -81,6 +82,8 @@ class form_step_instance extends \moodleform {
$mform->addElement('hidden', 'id'); // Save the record's id. $mform->addElement('hidden', 'id'); // Save the record's id.
$mform->setType('id', PARAM_TEXT); $mform->setType('id', PARAM_TEXT);
$mform->addElement('header', 'general_settings_header', get_string('general_settings_header', 'tool_cleanupcourses'));
$elementname = 'instancename'; $elementname = 'instancename';
$mform->addElement('text', $elementname, get_string('step_instancename', 'tool_cleanupcourses')); $mform->addElement('text', $elementname, get_string('step_instancename', 'tool_cleanupcourses'));
$mform->setType($elementname, PARAM_TEXT); $mform->setType($elementname, PARAM_TEXT);
...@@ -94,12 +97,20 @@ class form_step_instance extends \moodleform { ...@@ -94,12 +97,20 @@ class form_step_instance extends \moodleform {
$mform->setType($elementname, PARAM_TEXT); $mform->setType($elementname, PARAM_TEXT);
$elementname = 'followedby'; $elementname = 'followedby';
$mform->addElement('select', $elementname, get_string('step_followedby', 'tool_cleanupcourses'), $select = $mform->createElement('select', $elementname, get_string('step_followedby', 'tool_cleanupcourses'));
$stepmanager->get_step_instances()); $select->addOption(get_string('followedby_none', 'tool_cleanupcourses'), null);
foreach ($stepmanager->get_step_instances() as $key => $value) {
$select->addOption($value, $key);
}
$mform->addElement($select);
$mform->setType($elementname, PARAM_TEXT); $mform->setType($elementname, PARAM_TEXT);
// Insert the subplugin specific settings. // Insert the subplugin specific settings.
if (!empty($this->lib->instance_settings())) {
$mform->addElement('header', 'step_settings_header', get_string('step_settings_header', 'tool_cleanupcourses'));
$this->lib->extend_add_instance_form_definition($mform); $this->lib->extend_add_instance_form_definition($mform);
}
$this->add_action_buttons(); $this->add_action_buttons();
} }
......
...@@ -34,7 +34,9 @@ $string['subpluginssettings_trigger_heading'] = 'Trigger Definition'; ...@@ -34,7 +34,9 @@ $string['subpluginssettings_trigger_heading'] = 'Trigger Definition';
$string['subpluginssettings_step_heading'] = 'Step Workflow'; $string['subpluginssettings_step_heading'] = 'Step Workflow';
$string['subpluginssettings_edit_instance_heading'] = 'Step Instance'; $string['subpluginssettings_edit_instance_heading'] = 'Step Instance';
$string['add_new_step_instance'] = 'Add New Step Instance...'; $string['add_new_step_instance'] = 'Add New Step Instance...';
$string['step_settings_header'] = 'Specific settings of the step type';
$string['general_settings_header'] = 'General Settings';
$string['followedby_none'] = 'None';
$string['trigger_subpluginname'] = 'Subplugin Name'; $string['trigger_subpluginname'] = 'Subplugin Name';
$string['trigger_enabled'] = 'Enabled'; $string['trigger_enabled'] = 'Enabled';
......
...@@ -24,3 +24,6 @@ ...@@ -24,3 +24,6 @@
*/ */
$string['pluginname'] = 'Email Step'; $string['pluginname'] = 'Email Step';
$string['email_subject'] = 'Subject Template';
$string['email_content'] = 'Content Template';
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
$plugin->version = 2017051808; $plugin->version = 2017052202;
$plugin->component = 'tool_cleanupcourses'; $plugin->component = 'tool_cleanupcourses';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment