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

Workflows can now be created and viewed including their steps

parent ad08d74f
Branches
Tags
No related merge requests found
......@@ -16,12 +16,17 @@
namespace tool_cleanupcourses;
use tool_cleanupcourses\form\form_workflow_instance;
use tool_cleanupcourses\form\form_step_instance;
use tool_cleanupcourses\manager\step_manager;
use tool_cleanupcourses\manager\trigger_manager;
use tool_cleanupcourses\manager\settings_manager;
use tool_cleanupcourses\manager\trigger_manager;
use tool_cleanupcourses\entity\workflow;
use tool_cleanupcourses\entity\step_subplugin;
use tool_cleanupcourses\table\step_table;
use tool_cleanupcourses\manager\workflow_manager;
use tool_cleanupcourses\table\workflow_table;
use tool_cleanupcourses\table\trigger_table;
use tool_cleanupcourses\table\step_table;
defined('MOODLE_INTERNAL') || die;
......@@ -131,12 +136,140 @@ class subplugin_settings {
echo $OUTPUT->heading(get_string('subpluginssettings_step_heading', 'tool_cleanupcourses'));
echo $OUTPUT->single_button(new \moodle_url($PAGE->url,
array('action' => ACTION_ADD_WORKFLOW, 'sesskey' => sesskey())),
get_string('add_workflow', 'tool_cleanupcourses'));
$table = new workflow_table('tool_cleanupcourses_workflows');
$table->out(5000, false);
$this->view_footer();
}
/**
* Write the HTML for the add workflow form.
* @param form_workflow_instance $form
*/
private function view_workflow_instance_form($form) {
global $OUTPUT;
// Set up the table.
$this->view_header();
echo $OUTPUT->heading(get_string('subpluginssettings_edit_workflow_instance_heading', 'tool_cleanupcourses'));
echo $form->render();
$this->view_footer();
}
/**
* Write the page header
*/
private function view_header() {
global $OUTPUT;
// Print the page heading.
echo $OUTPUT->header();
}
/**
* Write the page footer
*/
private function view_footer() {
global $OUTPUT;
echo $OUTPUT->footer();
}
/**
* Check this user has permission to edit the subplugin settings
*/
private function check_permissions() {
// Check permissions.
require_login();
$systemcontext = \context_system::instance();
require_capability('moodle/site:config', $systemcontext);
}
/**
* This is the entry point for this controller class.
*/
public function execute($action, $subpluginid, $workflowid) {
global $PAGE;
$this->check_permissions();
// Has to be called before moodleform is created!
admin_externalpage_setup('tool_cleanupcourses_subpluginssettings');
trigger_manager::handle_action($action, $subpluginid);
workflow_manager::handle_action($action, $workflowid);
$form = new form_workflow_instance($PAGE->url, $workflowid);
if ($action === ACTION_ADD_WORKFLOW) {
$this->view_workflow_instance_form($form);
} else {
if ($form->is_submitted() && !$form->is_cancelled() && $data = $form->get_submitted_data()) {
if ($data->id) {
$workflow = workflow_manager::get_workflow($data->id);
$workflow->title = $data->title;
} else {
$workflow = workflow::from_record($data);
}
workflow_manager::insert_or_update($workflow);
}
$this->view_plugins_table();
}
}
}
/**
* Class that handles the display and configuration of a workflow.
*
* @package tool_cleanupcourses
* @copyright 2015 Tobias Reischmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class workflow_settings {
/** @var object the url of the subplugin settings page */
private $pageurl;
/** @var int id of the workflow the settings should be displayed for (null for new workflow).
*/
private $workflowid;
/**
* Constructor for this subplugin settings
*/
public function __construct($workflowid) {
global $PAGE;
// Has to be called before moodleform is created!
admin_externalpage_setup('tool_cleanupcourses_subpluginssettings');
$this->pageurl = new \moodle_url('/admin/tool/cleanupcourses/workflowsettings.php');
$PAGE->set_url($this->pageurl);
$this->workflowid = $workflowid;
}
/**
* Write the HTML for the submission plugins table.
*/
private function view_plugins_table() {
global $OUTPUT, $PAGE;
// Set up the table.
$this->view_header();
echo $OUTPUT->heading(get_string('subpluginssettings_step_heading', 'tool_cleanupcourses'));
$steps = step_manager::get_step_types();
echo $OUTPUT->single_select(new \moodle_url($PAGE->url,
array('action' => ACTION_STEP_INSTANCE_FORM, 'sesskey' => sesskey())),
array('action' => ACTION_STEP_INSTANCE_FORM, 'sesskey' => sesskey(), 'workflowid' => $this->workflowid)),
'subpluginname', $steps, '', array('' => get_string('add_new_step_instance', 'tool_cleanupcourses')));
echo $OUTPUT->single_button( new \moodle_url('/admin/tool/cleanupcourses/subpluginssettings.php'),
get_string('back'));
$table = new step_table('tool_cleanupcourses_steps');
$table = new step_table('tool_cleanupcourses_workflows', $this->workflowid);
$table->out(5000, false);
$this->view_footer();
......@@ -192,10 +325,6 @@ class subplugin_settings {
global $PAGE;
$this->check_permissions();
// Has to be called before moodleform is created!
admin_externalpage_setup('tool_cleanupcourses_subpluginssettings');
trigger_manager::handle_action($action, $subplugin);
step_manager::handle_action($action, $subplugin);
$steptomodify = null;
......@@ -216,13 +345,18 @@ class subplugin_settings {
return;
}
$form = new form_step_instance($PAGE->url, $steptomodify, $subpluginname, $stepsettings);
$form = new form_step_instance($PAGE->url, $steptomodify, $this->workflowid, $subpluginname, $stepsettings);
if ($action === ACTION_STEP_INSTANCE_FORM) {
$this->view_step_instance_form($form);
} else {
if ($form->is_submitted() && !$form->is_cancelled() && $data = $form->get_submitted_data()) {
$step = step_manager::get_step_instance($data->id);
if ($step) {
$step->instancename = $data->instancename;
} else {
$step = step_subplugin::from_record($data);
}
step_manager::insert_or_update($step);
// Save local subplugin settings.
settings_manager::save_settings($step->id, $form->subpluginname, $data);
......
......@@ -21,7 +21,7 @@
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_cleanupcourses;
namespace tool_cleanupcourses\form;
use tool_cleanupcourses\entity\step_subplugin;
use tool_cleanupcourses\manager\step_manager;
......@@ -58,6 +58,11 @@ class form_step_instance extends \moodleform {
*/
public $stepsettings;
/**
* @var int id of the workflow
*/
private $workflowid;
/**
* Constructor
* @param \moodle_url $url.
......@@ -66,8 +71,9 @@ class form_step_instance extends \moodleform {
* @param array $stepsettings settings of the step.
* @throws \moodle_exception if neither step nor subpluginname are set.
*/
public function __construct($url, $step, $subpluginname = null, $stepsettings = null) {
public function __construct($url, $step, $workflowid, $subpluginname = null, $stepsettings = null) {
$this->step = $step;
$this->workflowid = $workflowid;
if ($step) {
$this->subpluginname = $step->subpluginname;
} else if ($subpluginname) {
......@@ -90,6 +96,9 @@ class form_step_instance extends \moodleform {
$mform->addElement('hidden', 'id'); // Save the record's id.
$mform->setType('id', PARAM_TEXT);
$mform->addElement('hidden', 'workflowid'); // Save the record's id.
$mform->setType('workflowid', PARAM_INT);
$mform->addElement('header', 'general_settings_header', get_string('general_settings_header', 'tool_cleanupcourses'));
$elementname = 'instancename';
......@@ -103,15 +112,6 @@ class form_step_instance extends \moodleform {
$mform->addElement('hidden', $elementname);
$mform->setType($elementname, PARAM_TEXT);
$elementname = 'followedby';
$select = $mform->createElement('select', $elementname, get_string('step_followedby', 'tool_cleanupcourses'));
$select->addOption(get_string('followedby_none', 'tool_cleanupcourses'), null);
foreach (step_manager::get_step_instances() as $key => $value) {
$select->addOption($value, $key);
}
$mform->addElement($select);
$mform->setType($elementname, PARAM_TEXT);
// Insert the subplugin specific settings.
if (!empty($this->lib->instance_settings())) {
$mform->addElement('header', 'step_settings_header', get_string('step_settings_header', 'tool_cleanupcourses'));
......@@ -127,11 +127,12 @@ class form_step_instance extends \moodleform {
public function definition_after_data() {
$mform = $this->_form;
$mform->setDefault('workflowid', $this->workflowid);
if ($this->step) {
$mform->setDefault('id', $this->step->id);
$mform->setDefault('instancename', $this->step->instancename);
$subpluginname = $this->step->subpluginname;
$mform->setDefault('followedby', $this->step->followedby);
} else {
$mform->setDefault('id', '');
$subpluginname = $this->subpluginname;
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Offers the possibility to add or modify a workflow instance.
*
* @package tool_cleanupcourses
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_cleanupcourses\form;
use tool_cleanupcourses\entity\workflow;
use tool_cleanupcourses\manager\step_manager;
use tool_cleanupcourses\manager\lib_manager;
use tool_cleanupcourses\step\libbase;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
* Provides a form to modify a workflow instance
*/
class form_workflow_instance extends \moodleform {
/**
* @var workflow
*/
public $workflow;
/**
* Constructor
* @param \moodle_url $url.
* @param workflow $workflow workflow entity.
* @throws \moodle_exception if neither step nor subpluginname are set.
*/
public function __construct($url, $workflow) {
$this->workflow = $workflow;
parent::__construct($url);
}
/**
* Defines forms elements
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('hidden', 'id'); // Save the record's id.
$mform->setType('id', PARAM_TEXT);
$mform->addElement('header', 'general_settings_header', get_string('general_settings_header', 'tool_cleanupcourses'));
$elementname = 'title';
$mform->addElement('text', $elementname, get_string('workflow_title', 'tool_cleanupcourses'));
$mform->setType($elementname, PARAM_TEXT);
$mform->setDefault($elementname, $this->workflow->title);
$this->add_action_buttons();
}
}
......@@ -73,4 +73,13 @@ class workflow_manager {
}
return $result;
}
/**
* Handles an action of the subplugin_settings.
* @param string $action action to be executed
* @param int $workflowid id of the workflow
*/
public static function handle_action($action, $workflowid) {
}
}
......@@ -32,25 +32,31 @@ require_once(__DIR__ . '/../../lib.php');
class step_table extends \table_sql {
public function __construct($uniqueid) {
/** int workflowid */
private $workflowid;
public function __construct($uniqueid, $workflowid) {
parent::__construct($uniqueid);
global $PAGE;
$this->set_sql("id, subpluginname, instancename, followedby", '{tool_cleanupcourses_step}', "TRUE");
$this->workflowid = $workflowid;
$this->set_sql("id, subpluginname, instancename, sortindex",
'{tool_cleanupcourses_step}',
"workflowid = $workflowid");
$this->define_baseurl($PAGE->url);
$this->pageable(false);
$this->init();
}
public function init() {
$this->define_columns(['instancename', 'subpluginname', 'followedby', 'edit', 'delete']);
$this->define_columns(['instancename', 'subpluginname', 'sortindex', 'edit', 'delete']);
$this->define_headers([
get_string('step_instancename', 'tool_cleanupcourses'),
get_string('step_subpluginname', 'tool_cleanupcourses'),
get_string('step_followedby', 'tool_cleanupcourses'),
get_string('step_sortindex', 'tool_cleanupcourses'),
get_string('step_edit', 'tool_cleanupcourses'),
get_string('step_delete', 'tool_cleanupcourses'),
]);
$this->sortable(false);
$this->sortable(false, 'sortindex');
$this->setup();
}
......@@ -67,24 +73,33 @@ class step_table extends \table_sql {
}
/**
* Render followedby column.
* Render sortindex column.
* @param $row
* @return string action button for enabling/disabling of the subplugin
* @return string action buttons for changing sortorder of the subplugin
*/
public function col_followedby($row) {
global $PAGE, $OUTPUT;
$steps = step_manager::get_step_instances();
// Determine, which step is selected.
$selected = '';
if ($row->followedby !== null) {
$selected = (int) $row->followedby;
public function col_sortindex($row) {
global $OUTPUT;
$output = '';
if ($row->sortindex !== null) {
if ($row->sortindex > 1) {
$alt = 'up';
$icon = 't/up';
$action = ACTION_UP_STEP;
$output .= $this->format_icon_link($action, $row->id, $icon, get_string($alt));
} else {
$output .= $OUTPUT->spacer();
}
if ($row->sortindex < step_manager::count_steps_of_workflow($this->workflowid)) {
$alt = 'down';
$icon = 't/down';
$action = ACTION_DOWN_STEP;
$output .= $this->format_icon_link($action, $row->id, $icon, get_string($alt));
} else {
$output .= $OUTPUT->spacer();
}
}
return $OUTPUT->single_select(new \moodle_url($PAGE->url,
array('action' => ACTION_FOLLOWEDBY_STEP, 'subplugin' => $row->id, 'sesskey' => sesskey())),
'followedby', $steps, $selected);
return $output;
}
/**
......@@ -128,7 +143,10 @@ class step_table extends \table_sql {
global $PAGE, $OUTPUT;
return $OUTPUT->action_icon(new \moodle_url($PAGE->url,
array('action' => $action, 'subplugin' => $subpluginid, 'sesskey' => sesskey())),
array('action' => $action,
'subplugin' => $subpluginid,
'sesskey' => sesskey(),
'workflowid' => $this->workflowid)),
new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null, array('title' => $alt)) . ' ';
}
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Table listing workflows.
*
* @package tool_cleanupcourses
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_cleanupcourses\table;
use tool_cleanupcourses\manager\step_manager;
use tool_cleanupcourses\manager\trigger_manager;
use tool_cleanupcourses\manager\workflow_manager;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/tablelib.php');
require_once(__DIR__ . '/../../lib.php');
class workflow_table extends \table_sql {
public function __construct($uniqueid) {
parent::__construct($uniqueid);
global $PAGE;
$this->set_sql("id, title, timeactive", '{tool_cleanupcourses_workflow}', "TRUE");
$this->define_baseurl($PAGE->url);
$this->pageable(false);
$this->init();
}
public function init() {
$this->define_columns(['title', 'timeactive', 'tools']);
$this->define_headers([
get_string('workflow_title', 'tool_cleanupcourses'),
get_string('workflow_timeactive', 'tool_cleanupcourses'),
get_string('workflow_tools', 'tool_cleanupcourses'),
]);
$this->sortable(false, 'workflow_timeactive');
$this->setup();
}
/**
* Render tools column.
* @param $row
* @return string action buttons for workflows
*/
public function col_tools($row) {
global $OUTPUT;
$output = '';
$alt = 'edit';
$icon = 't/edit';
$url = new \moodle_url('/admin/tool/cleanupcourses/workflowsettings.php',
array('workflowid' => $row->id, 'sesskey' => sesskey()));
$output .= $OUTPUT->action_icon($url, new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null , array('title' => $alt));
return $output;
}
/**
* 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(),
'workflowid' => $this->workflowid)),
new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)),
null , array('title' => $alt)) . ' ';
}
}
\ No newline at end of file
......@@ -47,9 +47,15 @@ $string['trigger_enabled'] = 'Enabled';
$string['trigger_sortindex'] = 'Up/Down';
$string['trigger_workflow'] = 'Workflow';
$string['add_workflow'] = 'Add Workflow';
$string['workflow_title'] = 'Title';
$string['workflow_active'] = 'Active';
$string['workflow_timeactive'] = 'Active since';
$string['workflow_tools'] = 'Tools';
$string['step_subpluginname'] = 'Step Type';
$string['step_instancename'] = 'Instance Name';
$string['step_followedby'] = 'Followed by';
$string['step_sortindex'] = 'Up/Down';
$string['step_edit'] = 'Edit';
$string['step_delete'] = 'Delete';
......@@ -76,3 +82,5 @@ $string['nocoursestodisplay'] = 'There are currently no courses, which require y
$string['course_backups_list_header'] = 'Course Backups';
$string['backupcreated'] = 'Created at';
$string['restore'] = 'restore';
$string['workflownotfound'] = 'Workflow with id {$a} could not be found';
......@@ -31,3 +31,4 @@ define('ACTION_UP_STEP', 'up_step');
define('ACTION_DOWN_STEP', 'down_step');
define('ACTION_STEP_INSTANCE_FORM', 'step_instance_form');
define('ACTION_STEP_INSTANCE_DELETE', 'step_instance_delete');
define('ACTION_ADD_WORKFLOW', 'add_workflow');
\ No newline at end of file
......@@ -34,4 +34,5 @@ $PAGE->set_context(context_system::instance());
// Execute the controller.
$subpluginsettings->execute(optional_param('action', null, PARAM_TEXT),
optional_param('subplugin', null, PARAM_INT));
\ No newline at end of file
optional_param('subplugin', null, PARAM_INT),
optional_param('workflow', null, PARAM_INT));
\ No newline at end of file
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Display the list of active processes
*
* @package tool_cleanupcourses
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../../config.php');
require_login();
require_once(__DIR__ . '/adminlib.php');
$workflowid = required_param('workflowid', PARAM_INT);
$workflow = tool_cleanupcourses\manager\workflow_manager::get_workflow($workflowid);
if (!$workflow) {
throw new moodle_exception('workflownotfound', 'tool_cleanupcourses',
new \moodle_url('/admin/tool/cleanupcourses/subpluginssettings.php'), $workflowid);
}
// Create the class for this controller.
$workflowsettings = new tool_cleanupcourses\workflow_settings($workflowid);
$PAGE->set_context(context_system::instance());
// Execute the controller.
$workflowsettings->execute(optional_param('action', null, PARAM_TEXT),
optional_param('subplugin', null, PARAM_INT));
\ 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