From: toyomoyo Date: Thu, 4 Oct 2007 08:22:55 +0000 (+0000) Subject: MDL-11580, hide quiz grades when user has no grade:viewhidden capability and quiz... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=fb72e817d9bdeb1604f3188604277ad62dda17e5;p=moodle.git MDL-11580, hide quiz grades when user has no grade:viewhidden capability and quiz is still open, need $CFG->openuniversityhacks flag set --- diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index e451724fca..9a17564bd8 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -707,6 +707,8 @@ function quiz_get_renderoptions($reviewoptions, $state) { * correct_responses, solutions and general feedback */ function quiz_get_reviewoptions($quiz, $attempt, $context=null) { + + global $CFG; $options = new stdClass; $options->readonly = true; @@ -717,7 +719,15 @@ function quiz_get_reviewoptions($quiz, $attempt, $context=null) { // The teacher should be shown everything except during preview when the teachers // wants to see just what the students see $options->responses = true; - $options->scores = true; + + // MDL-11580, hide quiz report for teachers when they have no viewhidden capability + // need to check for other calls when context is not supplied + if (empty($CFG->openuniversityhacks) || ($context && has_capability('moodle/grade:viewhidden', $context))) { + $options->scores = true; + } else { + $options->scores = ($quiz->review & $quiz_state_mask & QUIZ_REVIEW_SCORES) ? 1 : 0; + } + $options->feedback = true; $options->correct_responses = true; $options->solutions = false; diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 71e2f321e8..49571f5e95 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -30,6 +30,12 @@ class quiz_report extends quiz_default_report { $this->print_header_and_tabs($cm, $course, $quiz, $reportmode="overview"); } + // MDL-11580, make a fake attempt object + // so that we can check whehter this user can view scores or not + $attempt->preview = false; + $attempt->timefinish = $quiz->timeopen; + $attemptoptions = quiz_get_reviewoptions($quiz, $attempt, $context); + // Deal with actions $action = optional_param('action', '', PARAM_ACTION); @@ -443,10 +449,11 @@ class quiz_report extends quiz_default_report { } if ($quiz->grade and $quiz->sumgrades) { + // MDL-11580, hide grades for OU teachers with no view hidden capability in open quiz if (!$download) { - $row[] = $attempt->sumgrades === NULL ? '-' : ''.round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints).''; + $row[] = ($attempt->sumgrades === NULL || !$attemptoptions->scores)? '-' : ''.round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints).''; } else { - $row[] = $attempt->sumgrades === NULL ? '-' : round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints); + $row[] = ($attempt->sumgrades === NULL || !$attemptoptions->scores) ? '-' : round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints); } } if($detailedmarks) { @@ -456,7 +463,8 @@ class quiz_report extends quiz_default_report { } } else { foreach($questionids as $questionid) { - if ($gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) { + // MDL-11580 + if (!$attemptoptions->scores && ($gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid))) { $grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $quiz->decimalpoints); } else { $grade = '--'; @@ -464,7 +472,7 @@ class quiz_report extends quiz_default_report { if (!$download) { $row[] = link_to_popup_window ('/mod/quiz/reviewquestion.php?state='.$gradedstateid.'&number='.$questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true); } else { - $row[] = $grade; + $row[] = $grade; } } }