Skip to content

Commit

Permalink
SV-24 Add an option for students to see results
Browse files Browse the repository at this point in the history
  • Loading branch information
odeialba committed Oct 13, 2023
1 parent cc4698b commit 71c7887
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 8 deletions.
2 changes: 1 addition & 1 deletion amd/build/sortvoting.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/sortvoting.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion amd/src/sortvoting.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ const saveVote = function(saveSortVoteElement) {
} else {
toastAdd(getString('voteerror', 'mod_sortvoting'), {type: 'danger'});
}
if (result.allowupdate) {
if (result.seeresultsupdated) {
// Reload the whole page so the results tab is visible now but wasn't before (or viceversa).
window.location.reload();
} else if (result.allowupdate) {
saveSortVoteElement.removeAttribute('disabled');
} else {
saveSortVoteElement.style.display = 'none';
Expand Down
14 changes: 13 additions & 1 deletion classes/external/save_vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@ public static function execute($sortvotingid, $votes) {
$context = \context_module::instance($cm->id);
self::validate_context($context);
\mod_sortvoting\permission::require_can_vote($context);
$canseeresultsold = \mod_sortvoting\permission::can_see_results($sortvoting, $context);

sortvoting_user_submit_response($sortvoting, $params['votes'], $course, $cm);

return ['success' => true, 'allowupdate' => (bool) $sortvoting->allowupdate];
$canseeresultsnew = \mod_sortvoting\permission::can_see_results($sortvoting, $context);

return [
'success' => true,
'allowupdate' => (bool) $sortvoting->allowupdate,
'seeresultsupdated' => (bool) $canseeresultsold !== $canseeresultsnew,
];
}

/**
Expand All @@ -95,6 +102,11 @@ public static function execute_returns() {
[
'success' => new external_value(PARAM_BOOL, 'Returns true on successful vote submision or throws an error'),
'allowupdate' => new external_value(PARAM_BOOL, 'Returns true if vote can be updated', VALUE_REQUIRED),
'seeresultsupdated' => new external_value(
PARAM_BOOL,
'Returns true if the user could not see the results and can see them now (or viceversa)',
VALUE_REQUIRED
),
]
);
}
Expand Down
Loading

0 comments on commit 71c7887

Please sign in to comment.