MDL-11580, hide quiz grades when user has no grade:viewhidden capability and quiz is still open, need $CFG->openuniversityhacks flag set

This commit is contained in:
toyomoyo 2007-10-04 08:22:55 +00:00
parent 5961dbfb10
commit fb72e817d9
2 changed files with 23 additions and 5 deletions

View File

@ -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;

View File

@ -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 ? '-' : '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints).'</a>';
$row[] = ($attempt->sumgrades === NULL || !$attemptoptions->scores)? '-' : '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints).'</a>';
} 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.'&amp;number='.$questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true);
} else {
$row[] = $grade;
$row[] = $grade;
}
}
}