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

Added functionality for deleting step instances

parent df2b1960
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,8 @@
namespace tool_cleanupcourses\manager;
use tool_cleanupcourses\object\step_subplugin;
use tool_cleanupcourses\object\trigger_subplugin;
use tool_cleanupcourses\manager\trigger_manager;
defined('MOODLE_INTERNAL') || die();
......@@ -63,18 +65,29 @@ class step_manager extends subplugin_manager {
}
/**
* Removes a subplugin from the database.
* @param step_subplugin $subplugin
* Removes a step instance from the database.
* @param int $stepinstanceid step instance id
*/
private function remove(step_subplugin &$subplugin) {
private function remove($stepinstanceid) {
global $DB;
$transaction = $DB->start_delegated_transaction();
$record = array(
'name' => $subplugin->name,
);
if ($record = $DB->get_record('tool_cleanupcourses_step', $record)) {
if ($record = $DB->get_record('tool_cleanupcourses_step', array('id' => $stepinstanceid))) {
$othersteps = $DB->get_records('tool_cleanupcourses_step', array('followedby' => $stepinstanceid));
foreach ($othersteps as $steprecord) {
$step = step_subplugin::from_record($steprecord);
$step->followedby = null;
$this->insert_or_update($step);
}
$othertrigger = $DB->get_records('tool_cleanupcourses_trigger', array('followedby' => $stepinstanceid));
foreach ($othertrigger as $triggerrecord) {
$trigger = trigger_subplugin::from_record($triggerrecord);
$trigger->followedby = null;
$triggermanager = new trigger_manager();
$triggermanager->insert_or_update($trigger);
}
$DB->delete_records('tool_cleanupcourses_step', (array) $record);
$subplugin = step_subplugin::from_record($record);
}
$transaction->allow_commit();
}
......@@ -142,5 +155,8 @@ class step_manager extends subplugin_manager {
if ($action === ACTION_FOLLOWEDBY_STEP) {
$this->change_followedby($subplugin, optional_param('followedby', null, PARAM_INT));
}
if ($action === ACTION_STEP_INSTANCE_DELETE) {
$this->remove($subplugin);
}
}
}
......@@ -174,7 +174,7 @@ class trigger_manager extends subplugin_manager {
* Persists a subplugin to the database.
* @param trigger_subplugin $subplugin
*/
private function insert_or_update(trigger_subplugin &$subplugin) {
public function insert_or_update(trigger_subplugin &$subplugin) {
global $DB;
$transaction = $DB->start_delegated_transaction();
if ($subplugin->id !== null) {
......
......@@ -42,11 +42,13 @@ class step_table extends \table_sql {
}
public function init() {
$this->define_columns(['instancename', 'name', 'followedby']);
$this->define_columns(['instancename', 'name', 'followedby', 'edit', 'delete']);
$this->define_headers([
get_string('step_instancename', 'tool_cleanupcourses'),
get_string('step_name', 'tool_cleanupcourses'),
get_string('step_followedby', 'tool_cleanupcourses'),
get_string('step_edit', 'tool_cleanupcourses'),
get_string('step_delete', 'tool_cleanupcourses'),
]);
$this->sortable(false);
$this->setup();
......@@ -86,4 +88,50 @@ class step_table extends \table_sql {
'followedby', $steps, $selected);
}
/**
* Render edit column.
* @param $row
* @return string action button for editing of the subplugin
*/
public function col_edit($row) {
$alt = 'edit';
$icon = 't/edit';
$action = ACTION_STEP_INSTANCE_EDIT;
return $this->format_icon_link($action, $row->id, $icon, get_string($alt));
}
/**
* Render delete column.
* @param $row
* @return string action button for deleting the subplugin
*/
public function col_delete($row) {
$alt = 'delete';
$icon = 't/delete';
$action = ACTION_STEP_INSTANCE_DELETE;
return $this->format_icon_link($action, $row->id, $icon, get_string($alt));
}
/**
* Util function for writing an action icon link
*
* @param string $action URL parameter to include in the link
* @param string $subpluginid URL parameter to include in the link
* @param string $icon The key to the icon to use (e.g. 't/up')
* @param string $alt The string description of the link used as the title and alt text
* @return string The icon/link
*/
private function format_icon_link($action, $subpluginid, $icon, $alt) {
global $PAGE, $OUTPUT;
return $OUTPUT->action_icon(new \moodle_url($PAGE->url,
array('action' => $action, 'subplugin' => $subpluginid, 'sesskey' => sesskey())),
new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null , array('title' => $alt)) . ' ';
}
}
\ No newline at end of file
......@@ -44,6 +44,8 @@ $string['trigger_followedby'] = 'Followed by';
$string['step_name'] = 'Step Type';
$string['step_instancename'] = 'Instance Name';
$string['step_followedby'] = 'Followed by';
$string['step_edit'] = 'Edit';
$string['step_delete'] = 'Delete';
$string['trigger'] = 'Trigger';
$string['step'] = 'Process step';
......
......@@ -29,3 +29,5 @@ define('ACTION_DOWN_TRIGGER', 'down');
define('ACTION_FOLLOWEDBY_TRIGGER', 'followedby_trigger');
define('ACTION_FOLLOWEDBY_STEP', 'followedby_step');
define('ACTION_STEP_INSTANCE_FORM', 'step_instance_form');
define('ACTION_STEP_INSTANCE_EDIT', 'step_instance_edit');
define('ACTION_STEP_INSTANCE_DELETE', 'step_instance_delete');
\ 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