[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/quiz/report/regrade/ -> report.php (source)

   1  <?php  // $Id: report.php,v 1.19.2.1 2007/11/02 16:20:37 tjhunt Exp $
   2  
   3  // This script regrades all attempts at this quiz
   4  require_once($CFG->libdir.'/tablelib.php');
   5  
   6  class quiz_report extends quiz_default_report {
   7  
   8      function display($quiz, $cm, $course) {
   9          global $CFG;
  10  
  11          // Print header
  12          $this->print_header_and_tabs($cm, $course, $quiz, $reportmode="regrade");
  13  
  14          // Check permissions
  15          $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  16          if (!has_capability('mod/quiz:grade', $context)) {
  17              notify(get_string('regradenotallowed', 'quiz'));
  18              return true;
  19          }
  20  
  21          // Fetch all attempts
  22          if (!$attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = 0")) {
  23              print_heading(get_string('noattempts', 'quiz'));
  24              return true;
  25          }
  26  
  27          // Fetch all questions
  28          $sql = "SELECT q.*, i.grade AS maxgrade FROM {$CFG->prefix}question q,
  29                                           {$CFG->prefix}quiz_question_instances i
  30                  WHERE i.quiz = $quiz->id
  31                  AND i.question = q.id";
  32  
  33          if (! $questions = get_records_sql($sql)) {
  34              error("Failed to get questions for regrading!");
  35          }
  36          get_question_options($questions);
  37  
  38          // Print heading
  39          print_heading(get_string('regradingquiz', 'quiz', format_string($quiz->name)));
  40          echo '<div class="boxaligncenter">';
  41          print_string('regradedisplayexplanation', 'quiz');
  42          echo '</div>';
  43  
  44          // Loop through all questions and all attempts and regrade while printing progress info
  45          foreach ($questions as $question) {
  46              echo '<strong>'.get_string('regradingquestion', 'quiz', $question->name).'</strong> '.get_string('attempts', 'quiz').": \n";
  47              foreach ($attempts as $attempt) {
  48                  set_time_limit(30);
  49                  $changed = regrade_question_in_attempt($question, $attempt, $quiz, true);
  50                  if ($changed) {
  51                      link_to_popup_window ('/mod/quiz/reviewquestion.php?attempt='.$attempt->id.'&amp;question='.$question->id,
  52                       'reviewquestion', ' #'.$attempt->id, 450, 550, get_string('reviewresponse', 'quiz'));
  53                  } else {
  54                      echo ' #'.$attempt->id;
  55                  }
  56              }
  57              echo '<br />';
  58              // the following makes sure that the output is sent immediately.
  59              @flush();@ob_flush();
  60          }
  61  
  62          // Loop through all questions and recalculate $attempt->sumgrade
  63          $attemptschanged = 0;
  64          foreach ($attempts as $attempt) {
  65              $sumgrades = 0;
  66              $questionids = explode(',', quiz_questions_in_quiz($attempt->layout));
  67              foreach($questionids as $questionid) {
  68                  $lastgradedid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->uniqueid, 'questionid', $questionid);
  69                  $sumgrades += get_field('question_states', 'grade', 'id', $lastgradedid);
  70              }
  71              if ($attempt->sumgrades != $sumgrades) {
  72                  $attemptschanged++;
  73                  set_field('quiz_attempts', 'sumgrades', $sumgrades, 'id', $attempt->id);
  74              }
  75          }
  76  
  77          // Update the overall quiz grades
  78          if ($grades = get_records('quiz_grades', 'quiz', $quiz->id)) {
  79              foreach($grades as $grade) {
  80                  quiz_save_best_grade($quiz, $grade->userid);
  81              }
  82          }
  83  
  84          return true;
  85      }
  86  }
  87  
  88  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7