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

Added form to add step instances

parent 098a843a
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\object\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;
...@@ -86,27 +87,52 @@ class subplugin_settings { ...@@ -86,27 +87,52 @@ class subplugin_settings {
* Constructor for this subplugin settings * Constructor for this subplugin settings
*/ */
public function __construct() { public function __construct() {
global $PAGE;
$this->pageurl = new \moodle_url('/admin/tool/cleanupcourses/subpluginssettings.php'); $this->pageurl = new \moodle_url('/admin/tool/cleanupcourses/subpluginssettings.php');
$PAGE->set_url($this->pageurl);
} }
/** /**
* Write the HTML for the submission plugins table. * Write the HTML for the submission plugins table.
*/ */
private function view_plugins_table() { private function view_plugins_table() {
global $OUTPUT, $PAGE;
// Set up the table. // Set up the table.
$this->view_header(); $this->view_header();
$table = new trigger_table('tool_cleanupcourses_triggers'); echo $OUTPUT->heading(get_string('subpluginssettings_trigger_heading', 'tool_cleanupcourses'));
$table = new trigger_table('tool_cleanupcourses_triggers');
$table->out(5000, false); $table->out(5000, false);
echo $OUTPUT->heading(get_string('subpluginssettings_step_heading', 'tool_cleanupcourses'));
echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('action' => ACTION_STEP_INSTANCE_FORM)),
get_string('add_instance', 'tool_cleanupcourses'));
$table = new step_table('tool_cleanupcourses_steps'); $table = new step_table('tool_cleanupcourses_steps');
$table->out(5000, false); $table->out(5000, false);
$this->view_footer(); $this->view_footer();
} }
/**
* Write the HTML for the step instance form.
*/
private function view_step_instance_form($form) {
global $OUTPUT;
// Set up the table.
$this->view_header();
echo $OUTPUT->heading(get_string('subpluginssettings_edit_instance_heading', 'tool_cleanupcourses'));
echo $form->render();
$this->view_footer();
}
/** /**
* Write the page header * Write the page header
*/ */
...@@ -115,7 +141,6 @@ class subplugin_settings { ...@@ -115,7 +141,6 @@ class subplugin_settings {
admin_externalpage_setup('subpluginssettings'); admin_externalpage_setup('subpluginssettings');
// Print the page heading. // Print the page heading.
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('subpluginssettings_heading', 'tool_cleanupcourses'));
} }
/** /**
...@@ -140,12 +165,29 @@ class subplugin_settings { ...@@ -140,12 +165,29 @@ class subplugin_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;
$this->check_permissions(); $this->check_permissions();
$triggermanager = new trigger_manager(); $triggermanager = new trigger_manager();
$triggermanager->handle_action($action, $subplugin); $triggermanager->handle_action($action, $subplugin);
$stepmanager = new step_manager(); $stepmanager = new step_manager();
$stepmanager->handle_action($action, $subplugin); $stepmanager->handle_action($action, $subplugin);
$steptomodify = null;
if ($stepid = optional_param('stepid', null, PARAM_INT)) {
$steptomodify = $stepmanager->get_subplugin_by_id($stepid);
}
$form = new form_step_instance($PAGE->url, $steptomodify);
if ($action === ACTION_STEP_INSTANCE_FORM) {
$this->view_step_instance_form($form);
} else {
if ($form->is_submitted() && !$form->is_cancelled()) {
$step = step_subplugin::from_record($form->get_submitted_data());
$stepmanager->insert_or_update($step);
}
$this->view_plugins_table(); $this->view_plugins_table();
} }
}
} }
\ 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/>.
/**
* Offers the possibility to add or modify a step 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;
use tool_cleanupcourses\object\step_subplugin;
use tool_cleanupcourses\manager\step_manager;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
* Provides a form to modify a step instance
*/
class form_step_instance extends \moodleform {
/**
* @var step_subplugin
*/
public $step;
/**
* Constructor
* @param string $url
* @param step_subplugin $step
*/
public function __construct($url, $step) {
parent::__construct($url);
$this->step = $step;
}
/**
* Defines forms elements
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('hidden', 'id'); // Save the record's id.
$mform->setType('id', PARAM_TEXT);
$elementname = 'instancename';
$mform->addElement('text', $elementname, get_string('step_instancename', 'tool_cleanupcourses'));
$mform->setType($elementname, PARAM_TEXT);
$stepmanager = new step_manager();
$elementname = 'name';
$mform->addElement('select', $elementname, get_string('step_name', 'tool_cleanupcourses'),
$stepmanager->get_step_types());
$mform->setType($elementname, PARAM_TEXT);
$this->add_action_buttons();
}
/**
* Defines forms elements
*/
public function definition_after_data() {
$mform = $this->_form;
if ($this->step) {
$mform->setDefault('id', $this->step->id);
$mform->setDefault('instancename', $this->step->instancename);
$mform->setDefault('name', $this->step->name);
} else {
$mform->setDefault('id', '');
}
}
}
...@@ -49,17 +49,13 @@ class step_manager extends subplugin_manager { ...@@ -49,17 +49,13 @@ class step_manager extends subplugin_manager {
* Persists a subplugin to the database. * Persists a subplugin to the database.
* @param step_subplugin $subplugin * @param step_subplugin $subplugin
*/ */
private function insert_or_update(step_subplugin &$subplugin) { public function insert_or_update(step_subplugin &$subplugin) {
global $DB; global $DB;
$transaction = $DB->start_delegated_transaction(); $transaction = $DB->start_delegated_transaction();
if ($subplugin->id !== null) { if ($subplugin->id) {
$DB->update_record('tool_cleanupcourses_step', $subplugin); $DB->update_record('tool_cleanupcourses_step', $subplugin);
} } else {
$record = array( $subplugin->id = $DB->insert_record('tool_cleanupcourses_step', $subplugin);
'name' => $subplugin->name,
);
if (!$DB->record_exists('tool_cleanupcourses_step', $record)) {
$subplugin->id = $DB->insert_record('tool_cleanupcourses_step', $record);
$record = $DB->get_record('tool_cleanupcourses_step', array('id' => $subplugin->id)); $record = $DB->get_record('tool_cleanupcourses_step', array('id' => $subplugin->id));
$subplugin = step_subplugin::from_record($record); $subplugin = step_subplugin::from_record($record);
} }
...@@ -92,6 +88,19 @@ class step_manager extends subplugin_manager { ...@@ -92,6 +88,19 @@ class step_manager extends subplugin_manager {
return $DB->get_records('tool_cleanupcourses_step'); return $DB->get_records('tool_cleanupcourses_step');
} }
/**
* Gets the list of step subplugins.
* @return array of step subplugins.
*/
public function get_step_types() {
$subplugins = \core_component::get_plugin_list('cleanupcoursesstep');
$result = array();
foreach ($subplugins as $id => $plugin) {
$result[$id] = get_string('pluginname', 'cleanupcoursesstep_' . $id);
}
return $result;
}
/** /**
* Changes the followedby of a trigger. * Changes the followedby of a trigger.
* @param int $subpluginid id of the trigger * @param int $subpluginid id of the trigger
......
...@@ -30,6 +30,11 @@ $string['plugintitle'] = 'Cleanup Courses'; ...@@ -30,6 +30,11 @@ $string['plugintitle'] = 'Cleanup Courses';
$string['general_config_header'] = "General & Subplugins"; $string['general_config_header'] = "General & Subplugins";
$string['active_processes_list_header'] = 'Active Processes'; $string['active_processes_list_header'] = 'Active Processes';
$string['subpluginssettings_heading'] = 'Subplugin Workflow'; $string['subpluginssettings_heading'] = 'Subplugin Workflow';
$string['subpluginssettings_trigger_heading'] = 'Trigger Definition';
$string['subpluginssettings_step_heading'] = 'Step Workflow';
$string['subpluginssettings_edit_instance_heading'] = 'Step Instance';
$string['add_instance'] = 'Add Instance';
$string['trigger_name'] = 'Subplugin Name'; $string['trigger_name'] = 'Subplugin Name';
$string['trigger_enabled'] = 'Enabled'; $string['trigger_enabled'] = 'Enabled';
...@@ -46,6 +51,9 @@ $string['step'] = 'Process step'; ...@@ -46,6 +51,9 @@ $string['step'] = 'Process step';
$string['cleanupcoursestrigger'] = 'Trigger'; $string['cleanupcoursestrigger'] = 'Trigger';
$string['cleanupcoursesstep'] = 'Process step'; $string['cleanupcoursesstep'] = 'Process step';
$string['step_instancename'] = 'Instance Name';
$string['step_name'] = 'Step Type';
$string['subplugintype_cleanupcoursestrigger'] = 'Trigger for starting the course cleanup'; $string['subplugintype_cleanupcoursestrigger'] = 'Trigger for starting the course cleanup';
$string['subplugintype_cleanupcoursestrigger_plural'] = 'Triggers for starting the course cleanup'; $string['subplugintype_cleanupcoursestrigger_plural'] = 'Triggers for starting the course cleanup';
$string['subplugintype_cleanupcoursesstep'] = 'Step within a course cleanup process'; $string['subplugintype_cleanupcoursesstep'] = 'Step within a course cleanup process';
......
...@@ -28,3 +28,4 @@ define('ACTION_UP_TRIGGER', 'up'); ...@@ -28,3 +28,4 @@ define('ACTION_UP_TRIGGER', 'up');
define('ACTION_DOWN_TRIGGER', 'down'); define('ACTION_DOWN_TRIGGER', 'down');
define('ACTION_FOLLOWEDBY_TRIGGER', 'followedby_trigger'); define('ACTION_FOLLOWEDBY_TRIGGER', 'followedby_trigger');
define('ACTION_FOLLOWEDBY_STEP', 'followedby_step'); define('ACTION_FOLLOWEDBY_STEP', 'followedby_step');
define('ACTION_STEP_INSTANCE_FORM', 'step_instance_form');
\ No newline at end of file
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
$plugin->version = 2017051807; $plugin->version = 2017051808;
$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