Skip to content

Commit

Permalink
StudentQuiz: Student can view and attempt the questions that belong t…
Browse files Browse the repository at this point in the history
…o the other group #703356
  • Loading branch information
Khoa Nguyen Dang committed Aug 10, 2023
1 parent 245594b commit 9738ab4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
$navinfo->total = $questionscount;
$PAGE->navbar->add(get_string('nav_question_no', 'studentquiz', $navinfo));

utils::require_access_to_a_relevant_group($cm, $context);
utils::require_access_to_a_relevant_group($cm, $context, '', $studentquizquestion);

echo $OUTPUT->header();

Expand Down
15 changes: 11 additions & 4 deletions classes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,21 @@ public static function ensure_question_version_status_is_correct(int $questionid
* @param object $cm - The course module object.
* @param \context $context The context module.
* @param string $title Page's title.
* @param studentquiz_question|null $studentquizquestion Student quiz question object.
* @return void
*/
public static function require_access_to_a_relevant_group(object $cm, \context $context, string $title = ''): void {
global $COURSE, $PAGE;
$groupmode = (int)groups_get_activity_groupmode($cm, $COURSE);
public static function require_access_to_a_relevant_group(object $cm, \context $context, string $title = '',
studentquiz_question $studentquizquestion = null): void {
global $COURSE, $PAGE, $USER;
$groupmode = (int) groups_get_activity_groupmode($cm, $COURSE);
$currentgroup = groups_get_activity_group($cm, true);
$isallowaccessgroup = ($studentquizquestion === null) ||
groups_group_visible($studentquizquestion->get_groupid(), $COURSE, $cm, $USER->id);

if ($groupmode === SEPARATEGROUPS && !$currentgroup && !has_capability('moodle/site:accessallgroups', $context)) {
if ($groupmode === SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context) &&
(!$currentgroup || !$isallowaccessgroup)) {
// If the student quiz in separate groups mode and
// the user does not belong to the question group, an error message will be displayed.
$renderer = $PAGE->get_renderer('mod_studentquiz');
$renderer->render_error_message(get_string('error_permission', 'studentquiz'), $title);
exit();
Expand Down

0 comments on commit 9738ab4

Please sign in to comment.