Skip to content
Browse files

Merge branch 'MDL-25122' of git://github.com/timhunt/moodle

  • Loading branch information...
2 parents 915a20f + 79c6e3a commit 908053e21de88b7f594d7de33945c243794eac77 @stronk7 stronk7 committed Feb 22, 2011
Showing with 37 additions and 26 deletions.
  1. +23 −0 mod/quiz/attemptlib.php
  2. +1 −0 mod/quiz/lang/en/quiz.php
  3. +7 −11 mod/quiz/review.php
  4. +6 −15 mod/quiz/reviewquestion.php
View
23 mod/quiz/attemptlib.php
@@ -593,6 +593,29 @@ public function is_own_attempt() {
}
/**
+ * Is the current user allowed to review this attempt. This applies when
+ * {@link is_own_attempt()} returns false.
+ * @return bool whether the review should be allowed.
+ */
+ public function is_review_allowed() {
+ if (!$this->has_capability('mod/quiz:viewreports')) {
+ return false;
+ }
+
+ $cm = $this->get_cm();
+ if ($this->has_capability('moodle/site:accessallgroups') ||
+ groups_get_activity_groupmode($cm) != SEPARATEGROUPS) {
+ return true;
+ }
+
+ // Check the users have at least one group in common.
+ $teachersgroups = groups_get_activity_allowed_groups($cm);
+ $studentsgroups = groups_get_all_groups($cm->course, $this->attempt->userid, $cm->groupingid);
+ return $teachersgroups && $studentsgroups &&
+ array_intersect(array_keys($teachersgroups), array_keys($studentsgroups));
+ }
+
+ /**
* Check the appropriate capability to see whether this user may review their own attempt.
* If not, prints an error.
*/
View
1 mod/quiz/lang/en/quiz.php
@@ -531,6 +531,7 @@
$string['noquestionsonpage'] = 'Empty page';
$string['noresponse'] = 'No response';
$string['noreview'] = 'You are not allowed to review this quiz';
+$string['noreviewattempt'] = 'You are not allowed to review this attempt.';
$string['noreviewshort'] = 'Not permitted';
$string['noreviewuntil'] = 'You are not allowed to review this quiz until {$a}';
$string['noreviewuntilshort'] = 'Available {$a}';
View
18 mod/quiz/review.php
@@ -34,21 +34,17 @@
$accessmanager = $attemptobj->get_access_manager(time());
$options = $attemptobj->get_review_options();
-/// Permissions checks for normal users who do not have quiz:viewreports capability.
- if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
- /// Can't review other users' attempts.
- if (!$attemptobj->is_own_attempt()) {
- quiz_error($attemptobj->get_quiz(), 'notyourattempt');
- }
- /// Can't review during the attempt - send them back to the attempt page.
+ // Check permissions.
+ if ($attemptobj->is_own_attempt()) {
if (!$attemptobj->is_finished()) {
redirect($attemptobj->attempt_url(0, $page));
- }
- /// Can't review unless Students may review -> Responses option is turned on.
- if (!$options->responses) {
+ } else if (!$options->responses) {
$accessmanager->back_to_view_page($attemptobj->is_preview_user(),
- $accessmanager->cannot_review_message($options));
+ $accessmanager->cannot_review_message($attemptobj->get_attempt_state()));
}
+
+ } else if (!$attemptobj->is_review_allowed()) {
+ throw new moodle_quiz_exception($attemptobj, 'noreviewattempt');
}
/// Load the questions and states needed by this page.
View
21 mod/quiz/reviewquestion.php
@@ -32,34 +32,25 @@
$accessmanager = $attemptobj->get_access_manager(time());
$options = $attemptobj->get_review_options();
-/// Permissions checks for normal users who do not have quiz:viewreports capability.
- if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
- /// Can't review during the attempt - send them back to the attempt page.
+ // Check permissions.
+ if ($attemptobj->is_own_attempt()) {
if (!$attemptobj->is_finished()) {
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('cannotreviewopen', 'quiz'));
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
die;
- }
- /// Can't review other users' attempts.
- if (!$attemptobj->is_own_attempt()) {
- echo $OUTPUT->header();
- echo $OUTPUT->notification(get_string('notyourattempt', 'quiz'));
- echo $OUTPUT->close_window_button();
- echo $OUTPUT->footer();
- die;
- }
-
- /// Can't review unless Students may review -> Responses option is turned on.
- if (!$options->responses) {
+ } else if (!$options->responses) {
$accessmanager = $attemptobj->get_access_manager(time());
echo $OUTPUT->header();
echo $OUTPUT->notification($accessmanager->cannot_review_message($attemptobj->get_review_options()));
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
die;
}
+
+ } else if (!$attemptobj->is_review_allowed()) {
+ throw new moodle_quiz_exception($attemptobj, 'noreviewattempt');
}
/// Load the questions and states.

0 comments on commit 908053e

Please sign in to comment.
Something went wrong with that request. Please try again.