Skip to content
Snippets Groups Projects
Commit ea84a097 authored by Justus Dieckmann's avatar Justus Dieckmann
Browse files

Save and display interactions

parent 52a1d603
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
namespace tool_lifecycle\manager; namespace tool_lifecycle\manager;
use tool_lifecycle\entity\process;
use tool_lifecycle\processor; use tool_lifecycle\processor;
use tool_lifecycle\response\step_interactive_response; use tool_lifecycle\response\step_interactive_response;
...@@ -63,6 +64,8 @@ class interaction_manager { ...@@ -63,6 +64,8 @@ class interaction_manager {
$interactionlib = lib_manager::get_step_interactionlib($step->subpluginname); $interactionlib = lib_manager::get_step_interactionlib($step->subpluginname);
$response = $interactionlib->handle_interaction($process, $step, $action); $response = $interactionlib->handle_interaction($process, $step, $action);
self::save_interaction($process, $action);
switch ($response) { switch ($response) {
case step_interactive_response::still_processing(): case step_interactive_response::still_processing():
return false; return false;
...@@ -82,6 +85,23 @@ class interaction_manager { ...@@ -82,6 +85,23 @@ class interaction_manager {
return true; return true;
} }
/**
* @param process $process
* @throws \dml_exception
*/
public static function save_interaction($process, $action) {
global $DB, $USER;
$record = new \stdClass();
$record->userid = $USER->id;
$record->time = time();
$record->courseid = $process->courseid;
$record->processid = $process->id;
$record->workflowid = $process->workflowid;
$record->stepindex = $process->stepindex;
// TODO Save Action!
$DB->insert_record('tool_lifecycle_action_log', $record);
}
/** /**
* Returns the capability a user has to have to make decisions for a specific course within the step. * Returns the capability a user has to have to make decisions for a specific course within the step.
* @param string $subpluginname name of the step * @param string $subpluginname name of the step
......
<?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 past interactions
*
* @package tool_lifecycle
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle\table;
use core\plugininfo\format;
use tool_lifecycle\manager\interaction_manager;
use tool_lifecycle\manager\lib_manager;
use tool_lifecycle\manager\step_manager;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/tablelib.php');
class interaction_log_table extends \table_sql {
public function __construct($uniqueid, $courseids) {
parent::__construct($uniqueid);
global $PAGE;
$fields = "l.id as processid, c.id as courseid, c.fullname as coursefullname, w.title as workflow, " .
"s.id as stepinstanceid, s.instancename as stepinstancename, s.subpluginname as subpluginname, " .
"u.id as userid, " . get_all_user_name_fields(true, 'u') . ", l.time as time";
$from = '{tool_lifecycle_action_log} l join ' .
'{course} c on l.courseid = c.id join ' .
'{tool_lifecycle_workflow} w on l.workflowid = w.id join ' .
'{tool_lifecycle_step} s on l.workflowid = s.workflowid AND l.stepindex = s.sortindex join ' .
'{user} u on l.userid = u.id';
$ids = implode(',', $courseids);
$where = 'FALSE';
if ($ids) {
$where = 'l.courseid IN (' . $ids . ')';
}
$this->column_nosort = array('category', 'status', 'tools');
$this->set_sql($fields, $from, $where, []);
$this->define_baseurl($PAGE->url);
$this->init();
}
/**
* Initialises the columns of the table.
*/
public function init() {
$this->define_columns(['courseid', 'coursefullname', 'workflow', 'time', 'user']);
$this->define_headers([
get_string('course'),
get_string('fullnamecourse'),
get_string('workflow', 'tool_lifecycle'),
get_string('date'),
get_string('user'),
]);
$this->setup();
}
/**
* Render user column.
* @param $row
* @return string
*/
public function col_user($row) {
global $CFG;
return \html_writer::link($CFG->wwwroot . '/user/profile.php?id=' . $row->userid, fullname($row));
}
/**
* Render time column.
* @param $row
* @return string
* @throws \coding_exception
*/
public function col_time($row) {
$dateformat = get_string('strftimedatetime', 'core_langconfig');
return userdate($row->time, $dateformat);
}
/**
* Render courseid column.
* @param $row
* @return string course link
*/
public function col_courseid($row) {
return \html_writer::link(course_get_url($row->courseid), $row->courseid);
}
/**
* Render coursefullname column.
* @param $row
* @return string course link
*/
public function col_coursefullname($row) {
return \html_writer::link(course_get_url($row->courseid), $row->coursefullname);
}
public function print_nothing_to_display() {
global $OUTPUT;
// Render button to allow user to reset table preferences.
echo $this->render_reset_button();
$this->print_initials_bar();
echo $OUTPUT->box(get_string('nopastactions', 'tool_lifecycle'));
}
}
\ No newline at end of file
...@@ -30,6 +30,7 @@ use tool_lifecycle\manager\process_manager; ...@@ -30,6 +30,7 @@ use tool_lifecycle\manager\process_manager;
use tool_lifecycle\manager\settings_manager; use tool_lifecycle\manager\settings_manager;
use tool_lifecycle\manager\step_manager; use tool_lifecycle\manager\step_manager;
use tool_lifecycle\manager\trigger_manager; use tool_lifecycle\manager\trigger_manager;
use tool_lifecycle\table\interaction_log_table;
use tool_lifecycle\table\interaction_remaining_table; use tool_lifecycle\table\interaction_remaining_table;
use tool_lifecycle\table\interaction_attention_table; use tool_lifecycle\table\interaction_attention_table;
...@@ -74,6 +75,7 @@ class view_controller { ...@@ -74,6 +75,7 @@ class view_controller {
"WHERE p.courseid IN (". $listofcourseids . ")"); "WHERE p.courseid IN (". $listofcourseids . ")");
$requiresinteraction = array(); $requiresinteraction = array();
$remainingcourses = $arrayofcourseids;
foreach ($processes as $process) { foreach ($processes as $process) {
$step = step_manager::get_step_instance($process->stepinstanceid); $step = step_manager::get_step_instance($process->stepinstanceid);
...@@ -82,7 +84,7 @@ class view_controller { ...@@ -82,7 +84,7 @@ class view_controller {
if (has_capability($capability, \context_course::instance($process->courseid), null, false) && if (has_capability($capability, \context_course::instance($process->courseid), null, false) &&
!empty(interaction_manager::get_action_tools($step->subpluginname, $process->processid))) { !empty(interaction_manager::get_action_tools($step->subpluginname, $process->processid))) {
$requiresinteraction[] = $process->courseid; $requiresinteraction[] = $process->courseid;
unset($arrayofcourseids[$process->courseid]); unset($remainingcourses[$process->courseid]);
} }
} }
...@@ -95,11 +97,19 @@ class view_controller { ...@@ -95,11 +97,19 @@ class view_controller {
echo $renderer->box(""); echo $renderer->box("");
echo $renderer->heading(get_string('tablecoursesremaining', 'tool_lifecycle'), 3); echo $renderer->heading(get_string('tablecoursesremaining', 'tool_lifecycle'), 3);
$table2 = new interaction_remaining_table('tool_lifecycle_remaining', $arrayofcourseids); $table2 = new interaction_remaining_table('tool_lifecycle_remaining', $remainingcourses);
echo $renderer->box_start("lifecycle-enable-overflow lifecycle-table"); echo $renderer->box_start("lifecycle-enable-overflow lifecycle-table");
$table2->out(50, false); $table2->out(50, false);
echo $renderer->box_end(); echo $renderer->box_end();
echo $renderer->box("");
echo $renderer->heading(get_string('tablecourseslog', 'tool_lifecycle'), 3);
$table3 = new interaction_log_table('tool_lifecycle_log', $arrayofcourseids);
echo $renderer->box_start("lifecycle-enable-overflow lifecycle-table");
$table3->out(50, false);
echo $renderer->box_end();
} }
/** /**
......
...@@ -66,6 +66,7 @@ $string['trigger_enabled'] = 'Enabled'; ...@@ -66,6 +66,7 @@ $string['trigger_enabled'] = 'Enabled';
$string['trigger_sortindex'] = 'Up/Down'; $string['trigger_sortindex'] = 'Up/Down';
$string['trigger_workflow'] = 'Workflow'; $string['trigger_workflow'] = 'Workflow';
$string['workflow'] = 'Workflow';
$string['add_workflow'] = 'Add Workflow'; $string['add_workflow'] = 'Add Workflow';
$string['upload_workflow'] = 'Upload Workflow'; $string['upload_workflow'] = 'Upload Workflow';
$string['workflow_title'] = 'Title'; $string['workflow_title'] = 'Title';
...@@ -140,11 +141,14 @@ $string['workflownotfound'] = 'Workflow with id {$a} could not be found'; ...@@ -140,11 +141,14 @@ $string['workflownotfound'] = 'Workflow with id {$a} could not be found';
// View.php. // View.php.
$string['tablecoursesrequiringattention'] = 'Courses that require your attention'; $string['tablecoursesrequiringattention'] = 'Courses that require your attention';
$string['tablecoursesremaining'] = 'Remaining courses'; $string['tablecoursesremaining'] = 'Remaining courses';
$string['tablecourseslog'] = 'Past Actions';
$string['viewheading'] = 'Manage courses'; $string['viewheading'] = 'Manage courses';
$string['interaction_success'] = 'Action successfully saved.'; $string['interaction_success'] = 'Action successfully saved.';
$string['manual_trigger_success'] = 'Workflow started successfully.'; $string['manual_trigger_success'] = 'Workflow started successfully.';
$string['manual_trigger_process_existed'] = 'A workflow for this course already exists.'; $string['manual_trigger_process_existed'] = 'A workflow for this course already exists.';
$string['nopastactions'] = 'There are no past actions';
$string['workflow_started'] = 'Workflow started.'; $string['workflow_started'] = 'Workflow started.';
$string['workflow_is_running'] = 'Workflow is running.'; $string['workflow_is_running'] = 'Workflow is running.';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment