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

For each trigger a followed by step can be defined.

parent 6f19a6fb
No related branches found
No related tags found
No related merge requests found
...@@ -56,11 +56,15 @@ class step_manager extends subplugin_manager { ...@@ -56,11 +56,15 @@ class step_manager extends subplugin_manager {
* @param int $subpluginid id of the subplugin * @param int $subpluginid id of the subplugin
* @return trigger_subplugin * @return trigger_subplugin
*/ */
private function get_subplugin_by_id($subpluginid) { public function get_subplugin_by_id($subpluginid) {
global $DB; global $DB;
$record = $DB->get_record('tool_cleanupcourses_step', array('id' => $subpluginid)); $record = $DB->get_record('tool_cleanupcourses_step', array('id' => $subpluginid));
if ($record) {
$subplugin = subplugin::from_record($record); $subplugin = subplugin::from_record($record);
return $subplugin; return $subplugin;
} else {
return null;
}
} }
/** /**
...@@ -101,4 +105,13 @@ class step_manager extends subplugin_manager { ...@@ -101,4 +105,13 @@ class step_manager extends subplugin_manager {
$transaction->allow_commit(); $transaction->allow_commit();
} }
/**
* Gets the list of currently enabled trigger subplugins.
* @return array of enabled trigger subplugins.
*/
public function get_steps() {
global $DB;
return $DB->get_records('tool_cleanupcourses_step');
}
} }
...@@ -109,6 +109,34 @@ class trigger_manager extends subplugin_manager { ...@@ -109,6 +109,34 @@ class trigger_manager extends subplugin_manager {
$transaction->allow_commit(); $transaction->allow_commit();
} }
/**
* Changes the followedby of a trigger.
* @param int $subpluginid id of the trigger
* @param int $followedby id of the step
*/
public function change_followedby($subpluginid, $followedby) {
global $DB;
$transaction = $DB->start_delegated_transaction();
$subplugin = $this->get_subplugin_by_id($subpluginid);
if (!$subplugin) {
return; //TODO: Throw error.
}
$step_manager = new step_manager();
$step = $step_manager->get_subplugin_by_id($followedby);
// If step is not defined clear followedby.
if ($step) {
$subplugin->followedby = $step->id;
} else {
$subplugin->followedby = null;
}
$this->insert_or_update($subplugin);
$transaction->allow_commit();
}
/** /**
* Removes a subplugin from the sortindex and adjusts all other indizes. * Removes a subplugin from the sortindex and adjusts all other indizes.
* @param trigger_subplugin $toberemoved * @param trigger_subplugin $toberemoved
...@@ -132,8 +160,12 @@ class trigger_manager extends subplugin_manager { ...@@ -132,8 +160,12 @@ class trigger_manager extends subplugin_manager {
private function get_subplugin_by_id($subpluginid) { private function get_subplugin_by_id($subpluginid) {
global $DB; global $DB;
$record = $DB->get_record('tool_cleanupcourses_trigger', array('id' => $subpluginid)); $record = $DB->get_record('tool_cleanupcourses_trigger', array('id' => $subpluginid));
if ($record) {
$subplugin = trigger_subplugin::from_record($record); $subplugin = trigger_subplugin::from_record($record);
return $subplugin; return $subplugin;
} else {
return null;
}
} }
/** /**
...@@ -217,6 +249,9 @@ class trigger_manager extends subplugin_manager { ...@@ -217,6 +249,9 @@ class trigger_manager extends subplugin_manager {
if ($action === ACTION_DOWN_SUBPLUGIN) { if ($action === ACTION_DOWN_SUBPLUGIN) {
$this->change_sortindex($subplugin, false); $this->change_sortindex($subplugin, false);
} }
if ($action === ACTION_FOLLOWEDBY_SUBPLUGIN) {
$this->change_followedby($subplugin, optional_param('followedby', null, PARAM_INT));
}
} }
} }
...@@ -33,18 +33,19 @@ class trigger_table extends \table_sql { ...@@ -33,18 +33,19 @@ class trigger_table extends \table_sql {
public function __construct($uniqueid) { public function __construct($uniqueid) {
parent::__construct($uniqueid); parent::__construct($uniqueid);
global $PAGE; global $PAGE;
$this->set_sql("id, name, enabled, sortindex", '{tool_cleanupcourses_trigger}', "TRUE"); $this->set_sql("id, name, enabled, sortindex, followedby", '{tool_cleanupcourses_trigger}', "TRUE");
$this->define_baseurl($PAGE->url); $this->define_baseurl($PAGE->url);
$this->pageable(false); $this->pageable(false);
$this->init(); $this->init();
} }
public function init() { public function init() {
$this->define_columns(['name', 'enabled', 'sortindex']); $this->define_columns(['name', 'enabled', 'sortindex', 'followedby']);
$this->define_headers([ $this->define_headers([
get_string('subplugin_name', 'tool_cleanupcourses'), get_string('subplugin_name', 'tool_cleanupcourses'),
get_string('subplugin_enabled', 'tool_cleanupcourses'), get_string('subplugin_enabled', 'tool_cleanupcourses'),
get_string('subplugin_sortindex', 'tool_cleanupcourses') get_string('subplugin_sortindex', 'tool_cleanupcourses'),
get_string('subplugin_followedby', 'tool_cleanupcourses'),
]); ]);
$this->sortable(false, 'sortindex'); $this->sortable(false, 'sortindex');
$this->setup(); $this->setup();
...@@ -131,4 +132,30 @@ class trigger_table extends \table_sql { ...@@ -131,4 +132,30 @@ class trigger_table extends \table_sql {
null , array('title' => $alt)) . ' '; null , array('title' => $alt)) . ' ';
} }
/**
* Render followedby column.
* @param $row
* @return string action button for enabling/disabling of the subplugin
*/
public function col_followedby($row) {
global $PAGE, $OUTPUT;
$manager = new step_manager();
$steps = $manager->get_steps();
$options = array();
foreach ($steps as $id => $step) {
$options[$id] = get_string('pluginname', 'cleanupcoursesstep_' . $step->name);
}
// Determine, which step is selected.
$selected = '';
if ($row->followedby !== null) {
$selected = (int) $row->followedby;
}
return $OUTPUT->single_select(new \moodle_url($PAGE->url,
array('action' => ACTION_FOLLOWEDBY_SUBPLUGIN, 'subplugin' => $row->id, 'sesskey' => sesskey())),
'followedby', $options, $selected);
}
} }
\ No newline at end of file
...@@ -35,6 +35,7 @@ $string['subplugin_name'] = 'Subplugin Name'; ...@@ -35,6 +35,7 @@ $string['subplugin_name'] = 'Subplugin Name';
$string['subplugin_type'] = 'Subplugin Type'; $string['subplugin_type'] = 'Subplugin Type';
$string['subplugin_enabled'] = 'Enabled'; $string['subplugin_enabled'] = 'Enabled';
$string['subplugin_sortindex'] = 'Up/Down'; $string['subplugin_sortindex'] = 'Up/Down';
$string['subplugin_followedby'] = 'Followed by';
$string['trigger'] = 'Trigger'; $string['trigger'] = 'Trigger';
$string['step'] = 'Process step'; $string['step'] = 'Process step';
......
...@@ -26,3 +26,4 @@ define('ACTION_ENABLE_SUBPLUGIN', 'enable'); ...@@ -26,3 +26,4 @@ define('ACTION_ENABLE_SUBPLUGIN', 'enable');
define('ACTION_DISABLE_SUBPLUGIN', 'disable'); define('ACTION_DISABLE_SUBPLUGIN', 'disable');
define('ACTION_UP_SUBPLUGIN', 'up'); define('ACTION_UP_SUBPLUGIN', 'up');
define('ACTION_DOWN_SUBPLUGIN', 'down'); define('ACTION_DOWN_SUBPLUGIN', 'down');
define('ACTION_FOLLOWEDBY_SUBPLUGIN', 'followedby');
\ 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