]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11580, hide quiz grades when user has no grade:viewhidden capability and quiz...
authortoyomoyo <toyomoyo>
Thu, 4 Oct 2007 08:22:55 +0000 (08:22 +0000)
committertoyomoyo <toyomoyo>
Thu, 4 Oct 2007 08:22:55 +0000 (08:22 +0000)
mod/quiz/locallib.php
mod/quiz/report/overview/report.php

index e451724fca089ce66985bcc664687c540293aea4..9a17564bd86f7dc2b6a9a45f644de6c96f88c3da 100644 (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;
index 71e2f321e813d66591db901863f91f338bf4b477..49571f5e951891b4459a04a88ec1cb70043865a5 100644 (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;
                                 }
                             }
                         }