Skip to content
Snippets Groups Projects
Commit 1850c457 authored by TamaraGunkel's avatar TamaraGunkel
Browse files

Refactored view controller: Handle actions before displaying view

parent 21f8c3ec
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,9 @@
*/
namespace tool_cleanupcourses;
use core\notification;
use tool_cleanupcourses\manager\interaction_manager;
use tool_cleanupcourses\manager\process_manager;
use tool_cleanupcourses\manager\step_manager;
use tool_cleanupcourses\table\interaction_remaining_table;
use tool_cleanupcourses\table\interaction_attention_table;
......@@ -40,18 +42,11 @@ class view_controller {
/**
* Handles actions triggered in the view.php and displays the view.
*
* @param $action string triggered action code.
* @param $processid int id of the process the action was triggered for.
* @param $stepid int id of the step the action was triggerd for.
* @param \renderer_base $renderer
*
*/
public function handle_view($action, $processid, $stepid) {
global $USER, $DB, $OUTPUT;
// Handle action for step.
if ($action && $processid && $stepid) {
interaction_manager::handle_interaction($stepid, $processid, $action);
// TODO redirect.
}
public function handle_view($renderer) {
global $USER, $DB;
$courses = get_user_capability_course('tool/cleanupcourses:managecourses', $USER, false);
if (!$courses) {
......@@ -86,19 +81,46 @@ class view_controller {
}
}
echo $OUTPUT->heading(get_string('tablecoursesrequiringattention', 'tool_cleanupcourses'), 3);
echo $renderer->heading(get_string('tablecoursesrequiringattention', 'tool_cleanupcourses'), 3);
$table1 = new interaction_attention_table('tool_cleanupcourses_interaction', $requiresinteraction);
echo $OUTPUT->box_start();
echo $renderer->box_start();
$table1->out(50, false);
echo $OUTPUT->box_end();
echo $renderer->box_end();
echo $OUTPUT->box("");
echo $OUTPUT->heading(get_string('tablecoursesremaining', 'tool_cleanupcourses'), 3);
echo $renderer->box("");
echo $renderer->heading(get_string('tablecoursesremaining', 'tool_cleanupcourses'), 3);
$table2 = new interaction_remaining_table('tool_cleanupcourses_remaining', $arrayofcourseids);
echo $OUTPUT->box_start("cleanupcourses-enable-overflow");
echo $renderer->box_start("cleanupcourses-enable-overflow");
$table2->out(50, false);
echo $OUTPUT->box_end();
echo $renderer->box_end();
}
/**
* Handle the case that the user requested interaction.
*
* @param string $action triggered action code.
* @param int $processid id of the process the action was triggered for.
* @param int $stepid id of the step the action was triggered for.
*/
public function handle_interaction($action, $processid, $stepid) {
global $PAGE;
interaction_manager::handle_interaction($stepid, $processid, $action);
redirect($PAGE->url, get_string('interaction_success', 'tool_cleanupcourses'), null, notification::SUCCESS);
}
/**
* Handle the case that the user manually triggered a workflow.
*
* @param int $triggerid id of the trigger whose workflow was requested.
* @param int $courseid id of the course the workflow was requested for.
*/
public function handle_trigger($triggerid, $courseid) {
global $PAGE;
//interaction_manager::handle_interaction($stepid, $processid, $action);
redirect($PAGE->url, get_string('manual_trigger_success', 'tool_cleanupcourses'), null, notification::SUCCESS);
}
}
\ No newline at end of file
......@@ -116,6 +116,8 @@ $string['workflownotfound'] = 'Workflow with id {$a} could not be found';
$string['tablecoursesrequiringattention'] = 'Courses that require your attention';
$string['tablecoursesremaining'] = 'Remaining courses';
$string['viewheading'] = 'Manage courses';
$string['interaction_success'] = 'Action successfully saved.';
$string['manual_trigger_success'] = 'Workflow started successfully.';
$string['workflow_started'] = 'Workflow started.';
$string['workflow_is_running'] = 'Workflow is running.';
\ No newline at end of file
......@@ -33,10 +33,15 @@ $PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_url(new \moodle_url('/admin/tool/cleanupcourses/view.php'));
// Interaction params.
$action = optional_param('action', null, PARAM_ALPHA);
$processid = optional_param('processid', null, PARAM_INT);
$stepid = optional_param('stepid', null, PARAM_INT);
// Manual trigger params.
$triggerid = optional_param('triggerid', null, PARAM_INT);
$courseid = optional_param('courseid', null, PARAM_INT);
$PAGE->set_title(get_string('viewheading', 'tool_cleanupcourses'));
$PAGE->set_heading(get_string('viewheading', 'tool_cleanupcourses'));
......@@ -45,7 +50,17 @@ $renderer = $PAGE->get_renderer('tool_cleanupcourses');
echo $renderer->header();
$controller = new \tool_cleanupcourses\view_controller();
$controller->handle_view($action, $processid, $stepid);
if ($action !== null && $processid !== null && $stepid !== null) {
require_sesskey();
$controller->handle_interaction($action, $processid, $stepid);
exit;
} else if ($triggerid !== null && $courseid !== null) {
require_sesskey();
$controller->handle_trigger($triggerid, $courseid);
exit;
}
$controller->handle_view($renderer);
echo $renderer->footer();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment