diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 27a839b4690..06f6539f607 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -430,6 +430,7 @@ $string['quiz:grade'] = 'Grade quizzes manually'; $string['quiz:ignoretimelimits'] = 'Ignores time limit on quizzes'; $string['quiz:manage'] = 'Manage quizzes'; $string['quiz:preview'] = 'Preview quizzes'; +$string['quiz:reviewmyattempts'] = 'Review your own attempts'; $string['quiz:view'] = 'View quiz information'; $string['quiz:viewreports'] = 'View quiz reports'; $string['quizavailable'] = 'The quiz is available until: $a'; diff --git a/mod/quiz/db/access.php b/mod/quiz/db/access.php index 9d5adbb8162..18f02d69303 100644 --- a/mod/quiz/db/access.php +++ b/mod/quiz/db/access.php @@ -22,6 +22,7 @@ $mod_quiz_capabilities = array( // Ability to do the quiz as a 'student'. 'mod/quiz:attempt' => array( + 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, 'legacy' => array( @@ -29,6 +30,17 @@ $mod_quiz_capabilities = array( ) ), + // Ability for a 'Student' to review their previous attempts. Review by + // 'Teachers' is controlled by mod/quiz:viewreports. + 'mod/quiz:reviewmyattempts' => array( + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'student' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/quiz:attempt' + ), + // Edit the quiz settings, add and remove questions. 'mod/quiz:manage' => array( 'riskbitmask' => RISK_SPAM, diff --git a/mod/quiz/index.php b/mod/quiz/index.php index b28e7660268..1d6d903e829 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -53,15 +53,16 @@ } array_unshift($align, 'center'); - $showing = 'scores'; // default + $showing = ''; // default if (has_capability('mod/quiz:viewreports', $coursecontext)) { array_push($headings, get_string('attempts', 'quiz')); array_push($align, 'left'); $showing = 'stats'; - } else if (has_capability('mod/quiz:attempt', $coursecontext)) { + } else if (has_any_capability(array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $coursecontext)) { array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz')); array_push($align, 'left', 'left'); + $showing = 'scores'; // default } $table->head = $headings; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 3bb465e46ad..0e656ee7399 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1106,7 +1106,7 @@ function quiz_print_overview($courses, &$htmlarray) { // The $quiz objects returned by get_all_instances_in_course have the necessary $cm // fields set to make the following call work. $str .= '
".get_string("quiztimelimit","quiz", format_time($quiz->timelimit * 60))."
"; @@ -144,7 +145,7 @@ finish_page($course); } - if (!(has_capability('mod/quiz:attempt', $context) || has_capability('mod/quiz:preview', $context))) { + if (!has_any_capability(array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt', 'mod/quiz:preview'), $context)) { print_box('' . get_string('youneedtoenrol', 'quiz') . '
' . print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id, true) . '
', 'generalbox', 'notice'); @@ -229,9 +230,9 @@ // Add the attempt number, making it a link, if appropriate. if ($attempt->preview) { - $row[] = make_review_link(get_string('preview', 'quiz'), $quiz, $attempt); + $row[] = make_review_link(get_string('preview', 'quiz'), $quiz, $attempt, $context); } else { - $row[] = make_review_link($attempt->attempt, $quiz, $attempt); + $row[] = make_review_link($attempt->attempt, $quiz, $attempt, $context); } // prepare strings for time taken and date completed @@ -258,7 +259,7 @@ if ($markcolumn && $attempt->timefinish > 0) { if ($attemptoptions->scores) { - $row[] = make_review_link(round($attempt->sumgrades, $quiz->decimalpoints), $quiz, $attempt); + $row[] = make_review_link(round($attempt->sumgrades, $quiz->decimalpoints), $quiz, $attempt, $context); } else { $row[] = ''; } @@ -275,7 +276,7 @@ $table->rowclass[$attempt->attempt] = 'bestrow'; } - $row[] = make_review_link($formattedgrade, $quiz, $attempt); + $row[] = make_review_link($formattedgrade, $quiz, $attempt, $context); } else { $row[] = ''; } @@ -453,9 +454,13 @@ function finish_page($course) { } /** Make some text into a link to review the quiz, if that is appropriate. */ -function make_review_link($linktext, $quiz, $attempt) { - // If not even responses are to be shown in review then we don't allow any review - if (!($quiz->review & QUIZ_REVIEW_RESPONSES)) { +function make_review_link($linktext, $quiz, $attempt, $context) { + static $canreview = null; + if (is_null($canreview)) { + $canreview = has_capability('mod/quiz:reviewmyattempts', $context); + } + // If not even responses are to be shown in review then we don't allow any review, or does not have review capability. + if (!$canreview || !($quiz->review & QUIZ_REVIEW_RESPONSES)) { return $linktext; }