From 6d03fd9830d3c8dbd3965051682a670af4c311f2 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 16 Mar 2011 14:34:19 +0000 Subject: [PATCH] MDL-20636 Fix for Bug 11593 merged from our 1.9 version. #268 --- mod/quiz/index.php | 2 +- mod/quiz/lib.php | 8 +++++--- mod/quiz/locallib.php | 7 ++++++- mod/quiz/report/attemptsreport.php | 3 ++- mod/quiz/review.php | 2 +- mod/quiz/summary.php | 2 +- mod/quiz/view.php | 8 ++++---- question/behaviour/adaptive/renderer.php | 3 ++- question/behaviour/deferredcbm/renderer.php | 2 +- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/mod/quiz/index.php b/mod/quiz/index.php index b679a885fcb..eac25bbb786 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -168,7 +168,7 @@ foreach ($quizzes as $quiz) { $grade = ''; $feedback = ''; if ($quiz->grade && array_key_exists($quiz->id, grades)) { - if ($alloptions->marks) { + if ($alloptions->marks >= question_display_options::MARK_AND_MAX) { $a = new stdClass(); $a->grade = quiz_format_grade($quiz, $grades[$quiz->id]); $a->maxgrade = quiz_format_grade($quiz, $quiz->grade); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 6ee65e8980b..aa419bb2fd2 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -606,10 +606,12 @@ function quiz_grade_item_update($quiz, $grades = NULL) { mod_quiz_display_options::LATER_WHILE_OPEN); $closedreviewoptions = mod_quiz_display_options::make_from_quiz($quiz, mod_quiz_display_options::AFTER_CLOSE); - if (!$openreviewoptions->marks && !$closedreviewoptions->marks) { + if ($openreviewoptions->marks < question_display_options::MARK_AND_MAX && + $closedreviewoptions->marks < question_display_options::MARK_AND_MAX) { $params['hidden'] = 1; - } else if (!$openreviewoptions->marks && $closedreviewoptions->marks) { + } else if ($openreviewoptions->marks < question_display_options::MARK_AND_MAX && + $closedreviewoptions->marks >= question_display_options::MARK_AND_MAX) { if ($quiz->timeclose) { $params['hidden'] = $quiz->timeclose; } else { @@ -810,7 +812,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, $tmpactivity->content->attemptid = $attempt->id; $tmpactivity->content->attempt = $attempt->attempt; - if (quiz_has_grades($quiz) && $options->marks) { + if (quiz_has_grades($quiz) && $options->marks >= question_display_options::MARK_AND_MAX) { $tmpactivity->content->sumgrades = quiz_format_grade($quiz, $attempt->sumgrades); $tmpactivity->content->maxgrade = quiz_format_grade($quiz, $quiz->sumgrades); } else { diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index a6da4d9c1a9..d7385e866bc 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1043,13 +1043,16 @@ function quiz_get_review_options($quiz, $attempt, $context) { * for all attempts. */ function quiz_get_combined_reviewoptions($quiz, $attempts) { - $fields = array('marks', 'feedback', 'generalfeedback', 'rightanswer', 'overallfeedback'); + $fields = array('feedback', 'generalfeedback', 'rightanswer', 'overallfeedback'); $someoptions = new stdClass(); $alloptions = new stdClass(); foreach ($fields as $field) { $someoptions->$field = false; $alloptions->$field = true; } + $someoptions->marks = question_display_options::HIDDEN; + $alloptions->marks = question_display_options::MARK_AND_MAX; + foreach ($attempts as $attempt) { $attemptoptions = mod_quiz_display_options::make_from_quiz($quiz, quiz_attempt_state($quiz, $attempt)); @@ -1057,6 +1060,8 @@ function quiz_get_combined_reviewoptions($quiz, $attempts) { $someoptions->$field = $someoptions->$field || $attemptoptions->$field; $alloptions->$field = $alloptions->$field && $attemptoptions->$field; } + $someoptions->marks = max($someoptions->marks, $attemptoptions->marks); + $alloptions->marks = min($alloptions->marks, $attemptoptions->marks); } return array($someoptions, $alloptions); } diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index 55e0b5c7e82..802584060d8 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -63,7 +63,8 @@ abstract class quiz_attempt_report extends quiz_default_report { } $reviewoptions = mod_quiz_display_options::make_from_quiz($quiz, $when); - $this->showgrades = quiz_has_grades($quiz) && ($reviewoptions->marks || + $this->showgrades = quiz_has_grades($quiz) && + ($reviewoptions->marks >= question_display_options::MARK_AND_MAX || has_capability('moodle/grade:viewhidden', $this->context)); return $this->showgrades; diff --git a/mod/quiz/review.php b/mod/quiz/review.php index bf04b274d26..fbce4af15d9 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -176,7 +176,7 @@ if ($page == 0) { // Show marks (if the user is allowed to see marks at the moment). $grade = quiz_rescale_grade($attempt->sumgrades, $quiz, false); - if ($options->marks && quiz_has_grades($quiz)) { + if ($options->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades($quiz)) { if (!$attempt->timefinish) { $rows[] = '' . get_string('grade') . '' . diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php index dd1b996230a..791f7aeae8d 100644 --- a/mod/quiz/summary.php +++ b/mod/quiz/summary.php @@ -102,7 +102,7 @@ $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter' $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz')); $table->align = array('left', 'left'); $table->size = array('', ''); -$markscolumn = $displayoptions->marks; +$markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX; if ($markscolumn) { $table->head[] = get_string('marks', 'quiz'); $table->align[] = 'left'; diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 172d536f8ad..de86ca42190 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -170,9 +170,9 @@ if ($attempts) { $attemptcolumn = $quiz->attempts != 1; - $gradecolumn = $someoptions->marks && quiz_has_grades($quiz); + $gradecolumn = $someoptions->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades($quiz); $markcolumn = $gradecolumn && ($quiz->grade != $quiz->sumgrades); - $overallstats = $alloptions->marks; + $overallstats = $alloptions->marks >= question_display_options::MARK_AND_MAX; $feedbackcolumn = quiz_has_feedback($quiz) && $alloptions->overallfeedback; @@ -248,7 +248,7 @@ if ($attempts) { $row[] = $datecompleted; if ($markcolumn && $attempt->timefinish > 0) { - if ($attemptoptions->marks) { + if ($attemptoptions->marks >= question_display_options::MARK_AND_MAX) { $row[] = quiz_format_grade($quiz, $attempt->sumgrades); } else { $row[] = ''; @@ -259,7 +259,7 @@ if ($attempts) { $attemptgrade = quiz_rescale_grade($attempt->sumgrades, $quiz, false); if ($gradecolumn) { - if ($attemptoptions->marks && $attempt->timefinish > 0) { + if ($attemptoptions->marks >= question_display_options::MARK_AND_MAX && $attempt->timefinish > 0) { $formattedgrade = quiz_format_grade($quiz, $attemptgrade); // highlight the highest grade if appropriate if ($overallstats && !$attempt->preview && $numattempts > 1 && !is_null($mygrade) && diff --git a/question/behaviour/adaptive/renderer.php b/question/behaviour/adaptive/renderer.php index dceec94d245..2eb8793edb5 100644 --- a/question/behaviour/adaptive/renderer.php +++ b/question/behaviour/adaptive/renderer.php @@ -53,7 +53,8 @@ class qbehaviour_adaptive_renderer extends qbehaviour_renderer { // Try to find the last graded step. $gradedstep = $this->get_graded_step($qa); - if (is_null($gradedstep) || $qa->get_max_mark() == 0 || !$options->marks) { + if (is_null($gradedstep) || $qa->get_max_mark() == 0 || + $options->marks < question_display_options::MARK_AND_MAX) { return ''; } diff --git a/question/behaviour/deferredcbm/renderer.php b/question/behaviour/deferredcbm/renderer.php index 81891452851..72b1ca8117f 100644 --- a/question/behaviour/deferredcbm/renderer.php +++ b/question/behaviour/deferredcbm/renderer.php @@ -85,7 +85,7 @@ class qbehaviour_deferredcbm_renderer extends qbehaviour_renderer { question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty')))); } - if ($options->marks) { + if ($options->marks >= question_display_options::MARK_AND_MAX) { $a->rawmark = format_float( $qa->get_last_behaviour_var('_rawfraction') * $qa->get_max_mark(), $options->markdp); $a->mark = $qa->format_mark($options->markdp);