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

interaction table per user

parent eac60f4b
No related branches found
No related tags found
No related merge requests found
...@@ -36,27 +36,25 @@ class interaction_table extends \table_sql { ...@@ -36,27 +36,25 @@ class interaction_table extends \table_sql {
/** @var step_subplugin $stepinstance */ /** @var step_subplugin $stepinstance */
private $stepinstance; private $stepinstance;
public function __construct($uniqueid, $stepid) { public function __construct($uniqueid) {
parent::__construct($uniqueid); parent::__construct($uniqueid);
$this->stepinstance = step_manager::get_step_instance($stepid);
global $PAGE, $USER; global $PAGE, $USER;
$fields = 'p.id as processid, c.id as courseid, c.fullname as coursefullname, c.shortname as courseshortname'; $fields = 'p.id as processid, c.id as courseid, c.fullname as coursefullname, c.shortname as courseshortname, s.id as stepinstanceid, s.instancename as stepinstancename, s.subpluginname';
$from = '{tool_cleanupcourses_process} p join ' . $from = '{tool_cleanupcourses_process} p join ' .
'{course} c on p.courseid = c.id join ' . '{course} c on p.courseid = c.id join ' .
'{tool_cleanupcourses_step} s '. '{tool_cleanupcourses_step} s '.
'on p.workflowid = s.workflowid AND p.stepindex = s.sortindex'; 'on p.workflowid = s.workflowid AND p.stepindex = s.sortindex';
if (interaction_manager::show_relevant_courses_instance_dependent($this->stepinstance->subpluginname)) { // if (interaction_manager::show_relevant_courses_instance_dependent($this->stepinstance->subpluginname)) {
$where = 's.id = :stepid'; // $where = 's.id = :stepid';
$params = array('stepid' => $stepid); // $params = array('stepid' => $stepid);
} else { // } else {
$where = 's.subpluginname = :subpluginname'; // $where = 's.subpluginname = :subpluginname';
$params = array('subpluginname' => $this->stepinstance->subpluginname); // $params = array('subpluginname' => $this->stepinstance->subpluginname);
} // }
$capability = interaction_manager::get_relevant_capability($this->stepinstance->subpluginname); //$capability = interaction_manager::get_relevant_capability($this->stepinstance->subpluginname);
$courses = get_user_capability_course($capability, $USER, false); $courses = get_user_capability_course('tool_cleanupcourses/view:managecourse', $USER, false);
if ($courses) { if ($courses) {
$listofcourseids = array_reduce($courses, function ($course1, $course2) { $listofcourseids = array_reduce($courses, function ($course1, $course2) {
if (!$course1) { if (!$course1) {
...@@ -73,12 +71,12 @@ class interaction_table extends \table_sql { ...@@ -73,12 +71,12 @@ class interaction_table extends \table_sql {
} }
return $course1 . ',' . $course2; return $course1 . ',' . $course2;
}); });
$where .= ' AND p.courseid IN ('. $listofcourseids . ')'; $where = 'p.courseid IN ('. $listofcourseids . ')';
} else { } else {
$where .= ' AND FALSE'; $where = 'FALSE';
} }
$this->set_sql($fields, $from, $where, $params); $this->set_sql($fields, $from, $where, []);
$this->define_baseurl($PAGE->url); $this->define_baseurl($PAGE->url);
$this->init(); $this->init();
...@@ -130,10 +128,19 @@ class interaction_table extends \table_sql { ...@@ -130,10 +128,19 @@ class interaction_table extends \table_sql {
*/ */
public function col_tools($row) { public function col_tools($row) {
$output = ''; $output = '';
$tools = interaction_manager::get_action_tools($this->stepinstance->subpluginname, $row->processid); $step = step_manager::get_step_instance($row->stepinstanceid);
$capability = interaction_manager::get_relevant_capability($step->subpluginname);
if(has_capability($capability, \context_course::instance($row->courseid), null, false)) {
$tools = interaction_manager::get_action_tools($step->subpluginname, $row->processid);
foreach ($tools as $tool) { foreach ($tools as $tool) {
$output .= $this->format_icon_link($tool['action'], $row->processid, $tool['icon'], $tool['alt']); $output .= $this->format_icon_link($tool['action'], $row->processid, $step->id, $tool['icon'], $tool['alt']);
} }
}
else {
// TODO show explanation.
}
return $output; return $output;
} }
...@@ -143,7 +150,8 @@ class interaction_table extends \table_sql { ...@@ -143,7 +150,8 @@ class interaction_table extends \table_sql {
* @return string pluginname of the subplugin * @return string pluginname of the subplugin
*/ */
public function col_status($row) { public function col_status($row) {
return interaction_manager::get_status_message($this->stepinstance->subpluginname, $row->processid); $step = step_manager::get_step_instance($row->stepinstanceid);
return interaction_manager::get_status_message($step->subpluginname, $row->processid);
} }
/** /**
...@@ -151,16 +159,18 @@ class interaction_table extends \table_sql { ...@@ -151,16 +159,18 @@ class interaction_table extends \table_sql {
* *
* @param string $action URL parameter to include in the link * @param string $action URL parameter to include in the link
* @param string $processid URL parameter to include in the link * @param string $processid URL parameter to include in the link
* @param int $stepinstanceid ID of the step instance
* @param string $icon The key to the icon to use (e.g. 't/up') * @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 * @param string $alt The string description of the link used as the title and alt text
*
* @return string The icon/link * @return string The icon/link
*/ */
private function format_icon_link($action, $processid, $icon, $alt) { private function format_icon_link($action, $processid, $stepinstanceid, $icon, $alt) {
global $PAGE, $OUTPUT; global $PAGE, $OUTPUT;
return $OUTPUT->action_icon(new \moodle_url($PAGE->url, return $OUTPUT->action_icon(new \moodle_url($PAGE->url,
array( array(
'stepid' => $this->stepinstance->id, 'stepid' => $stepinstanceid,
'action' => $action, 'action' => $action,
'processid' => $processid, 'processid' => $processid,
'sesskey' => sesskey() 'sesskey' => sesskey()
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
$string['pluginname'] = 'Cleanup Courses'; $string['pluginname'] = 'Cleanup Courses';
$string['plugintitle'] = 'Cleanup Courses'; $string['plugintitle'] = 'Cleanup Courses';
$string['view:managecourse'] = 'May manage courses in tool_cleanupcourses';
$string['general_config_header'] = "General & Subplugins"; $string['general_config_header'] = "General & Subplugins";
$string['config_delay_duration'] = 'Duration of a course delay'; $string['config_delay_duration'] = 'Duration of a course delay';
$string['config_delay_duration_desc'] = 'Defines the time frame, which a course is excluded from the cleanup course, when rolled back via user interaction.'; $string['config_delay_duration_desc'] = 'Defines the time frame, which a course is excluded from the cleanup course, when rolled back via user interaction.';
......
...@@ -34,7 +34,7 @@ $capabilities = array( ...@@ -34,7 +34,7 @@ $capabilities = array(
'teacher' => CAP_PREVENT, 'teacher' => CAP_PREVENT,
'students' => CAP_PREVENT, 'students' => CAP_PREVENT,
), ),
'clonepermissionsfrom' => 'moodle/course:update' 'clonepermissionsfrom' => 'tool_cleanupcourses/view:managecourse'
), ),
); );
......
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
$plugin->version = 2018021302; $plugin->version = 2018022000;
$plugin->component = 'tool_cleanupcourses'; $plugin->component = 'tool_cleanupcourses';
...@@ -32,11 +32,11 @@ require_login(); ...@@ -32,11 +32,11 @@ require_login();
$PAGE->set_context(context_system::instance()); $PAGE->set_context(context_system::instance());
$PAGE->set_url(new \moodle_url('/admin/tool/cleanupcourses/view.php')); $PAGE->set_url(new \moodle_url('/admin/tool/cleanupcourses/view.php'));
$stepid = required_param('stepid', PARAM_INT); //$stepid = required_param('stepid', PARAM_INT);
$action = optional_param('action', null, PARAM_ALPHA); $action = optional_param('action', null, PARAM_ALPHA);
$processid = optional_param('processid', null, PARAM_INT); $processid = optional_param('processid', null, PARAM_INT);
$stepinstance = step_manager::get_step_instance($stepid); //$stepinstance = step_manager::get_step_instance($stepid);
$PAGE->set_title("Title"); $PAGE->set_title("Title");
$PAGE->set_heading("Heading"); $PAGE->set_heading("Heading");
...@@ -45,17 +45,17 @@ $renderer = $PAGE->get_renderer('tool_cleanupcourses'); ...@@ -45,17 +45,17 @@ $renderer = $PAGE->get_renderer('tool_cleanupcourses');
echo $renderer->header(); echo $renderer->header();
if (interaction_manager::interaction_available($stepinstance->subpluginname)) { //if (interaction_manager::interaction_available($stepinstance->subpluginname)) {
if ($action && $processid) { // if ($action && $processid) {
interaction_manager::handle_interaction($stepinstance->id, $processid, $action); // interaction_manager::handle_interaction($stepinstance->id, $processid, $action);
} // }
$table = new interaction_table('tool_cleanupcourses_interaction', $stepinstance->id); $table = new interaction_table('tool_cleanupcourses_interaction');
$table->out(50, false); $table->out(50, false);
} else { //} else {
echo get_string('nointeractioninterface', 'tool_cleanupcourses'); // echo get_string('nointeractioninterface', 'tool_cleanupcourses');
} //}
echo $renderer->footer(); echo $renderer->footer();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment