Skip to content

Commit

Permalink
Add user dependent availability to actions for interactive steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Memmel committed Feb 20, 2022
1 parent 4023e37 commit fb3b3fe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion classes/local/table/interaction_attention_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,24 @@ public function init() {
* @throws \invalid_parameter_exception
*/
public function col_tools($row) {
global $USER;
$output = '';
$step = step_manager::get_step_instance($row->stepinstanceid);

$tools = interaction_manager::get_action_tools($step->subpluginname, $row->processid);
$toolsstrings = array_map(fn($action) => $action['action'], $tools);

$availabletoolsstrings = lib_manager::get_step_interactionlib($step->subpluginname)->
get_available_actions_for_user($toolsstrings, $USER->id, $row->courseid);

foreach ($tools as $tool) {
$output .= $this->format_icon_link($tool['action'], $row->processid, $step->id, $tool['alt']);
// Only show actions which are valid actions and which are available to the current user.
if (in_array($tool['action'], $toolsstrings) && in_array($tool['action'], $availabletoolsstrings)) {
$output .= $this->format_icon_link($tool['action'], $row->processid, $step->id, $tool['alt']);
}
}
if (empty($output)) {
$output = get_string('noactionsavailable', 'tool_lifecycle');
}
return $output;
}
Expand Down
1 change: 1 addition & 0 deletions lang/de/tool_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@

$string['coursename'] = 'Kursname';
$string['lastaction'] = 'Letzte Aktion am';
$string['noactionsavailable'] = 'Sie können keine Aktion ausführen. Warten Sie, bis ein anderer User dies tut.';

$string['workflow_started'] = 'Workflow gestartet.';
$string['workflow_is_running'] = 'Workflow läuft.';
Expand Down
1 change: 1 addition & 0 deletions lang/en/tool_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@

$string['coursename'] = 'Course name';
$string['lastaction'] = 'Last action on';
$string['noactionsavailable'] = 'You cannot execute any action but have to wait for another user to handle this course.';
$string['anonymous_user'] = 'Anonymous User';

$string['workflow_started'] = 'Workflow started.';
Expand Down
19 changes: 19 additions & 0 deletions step/interactionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,23 @@ abstract public function handle_interaction($process, $step, $action = 'default'
public function get_due_date($processid, $stepid) {
return null;
}

/**
* Method to limit the actions to specific users. Returns all actions by default so if not overwritten all actions are available
* to any user. You can overwrite this method to filter the $actionstrings array according to your needs to limit the actions
* shown to the given user.
*
* Care: When overwriting this method you want to make sure that at least one user can use at least one action or have a timeout
* in your step to avoid any deadlocked workflows.
*
* @param array $actionstrings array of action strings. These should match the strings with the key 'action'
* in {@see get_action_tools} return array.
* @param int $userid the id of the user for whom the returned actions should be visible
* @param int $courseid the id of the currently handled course
* @return array the (possibly) filtered $actions array containing the strings of the actions which should be available to the
* given user
*/
public function get_available_actions_for_user(array $actionstrings, int $userid, int $courseid) : array {
return $actionstrings;
}
}

0 comments on commit fb3b3fe

Please sign in to comment.