[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/quiz/ -> review.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This page prints a review of a particular quiz attempt
  19   *
  20   * It is used either by the student whose attempts this is, after the attempt,
  21   * or by a teacher reviewing another's attempt during or afterwards.
  22   *
  23   * @package   mod_quiz
  24   * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  
  29  require_once(dirname(__FILE__) . '/../../config.php');
  30  require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  31  require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
  32  
  33  $attemptid = required_param('attempt', PARAM_INT);
  34  $page      = optional_param('page', 0, PARAM_INT);
  35  $showall   = optional_param('showall', null, PARAM_BOOL);
  36  
  37  $url = new moodle_url('/mod/quiz/review.php', array('attempt'=>$attemptid));
  38  if ($page !== 0) {
  39      $url->param('page', $page);
  40  } else if ($showall) {
  41      $url->param('showall', $showall);
  42  }
  43  $PAGE->set_url($url);
  44  
  45  $attemptobj = quiz_attempt::create($attemptid);
  46  $page = $attemptobj->force_page_number_into_range($page);
  47  
  48  // Now we can validate the params better, re-genrate the page URL.
  49  if ($showall === null) {
  50      $showall = $page == 0 && $attemptobj->get_default_show_all('review');
  51  }
  52  $PAGE->set_url($attemptobj->review_url(null, $page, $showall));
  53  
  54  // Check login.
  55  require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
  56  $attemptobj->check_review_capability();
  57  
  58  // Create an object to manage all the other (non-roles) access rules.
  59  $accessmanager = $attemptobj->get_access_manager(time());
  60  $accessmanager->setup_attempt_page($PAGE);
  61  
  62  $options = $attemptobj->get_display_options(true);
  63  
  64  // Check permissions.
  65  if ($attemptobj->is_own_attempt()) {
  66      if (!$attemptobj->is_finished()) {
  67          redirect($attemptobj->attempt_url(null, $page));
  68  
  69      } else if (!$options->attempt) {
  70          $accessmanager->back_to_view_page($PAGE->get_renderer('mod_quiz'),
  71                  $attemptobj->cannot_review_message());
  72      }
  73  
  74  } else if (!$attemptobj->is_review_allowed()) {
  75      throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt');
  76  }
  77  
  78  // Load the questions and states needed by this page.
  79  if ($showall) {
  80      $questionids = $attemptobj->get_slots();
  81  } else {
  82      $questionids = $attemptobj->get_slots($page);
  83  }
  84  
  85  // Save the flag states, if they are being changed.
  86  if ($options->flags == question_display_options::EDITABLE && optional_param('savingflags', false,
  87          PARAM_BOOL)) {
  88      require_sesskey();
  89      $attemptobj->save_question_flags();
  90      redirect($attemptobj->review_url(null, $page, $showall));
  91  }
  92  
  93  // Work out appropriate title and whether blocks should be shown.
  94  if ($attemptobj->is_preview_user() && $attemptobj->is_own_attempt()) {
  95      $strreviewtitle = get_string('reviewofpreview', 'quiz');
  96      navigation_node::override_active_url($attemptobj->start_attempt_url());
  97  
  98  } else {
  99      $strreviewtitle = get_string('reviewofattempt', 'quiz', $attemptobj->get_attempt_number());
 100      if (empty($attemptobj->get_quiz()->showblocks) && !$attemptobj->is_preview_user()) {
 101          $PAGE->blocks->show_only_fake_blocks();
 102      }
 103  }
 104  
 105  // Set up the page header.
 106  $headtags = $attemptobj->get_html_head_contributions($page, $showall);
 107  $PAGE->set_title($attemptobj->get_quiz_name());
 108  $PAGE->set_heading($attemptobj->get_course()->fullname);
 109  
 110  // Summary table start. ============================================================================
 111  
 112  // Work out some time-related things.
 113  $attempt = $attemptobj->get_attempt();
 114  $quiz = $attemptobj->get_quiz();
 115  $overtime = 0;
 116  
 117  if ($attempt->state == quiz_attempt::FINISHED) {
 118      if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
 119          if ($quiz->timelimit && $timetaken > ($quiz->timelimit + 60)) {
 120              $overtime = $timetaken - $quiz->timelimit;
 121              $overtime = format_time($overtime);
 122          }
 123          $timetaken = format_time($timetaken);
 124      } else {
 125          $timetaken = "-";
 126      }
 127  } else {
 128      $timetaken = get_string('unfinished', 'quiz');
 129  }
 130  
 131  // Prepare summary informat about the whole attempt.
 132  $summarydata = array();
 133  if (!$attemptobj->get_quiz()->showuserpicture && $attemptobj->get_userid() != $USER->id) {
 134      // If showuserpicture is true, the picture is shown elsewhere, so don't repeat it.
 135      $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
 136      $usrepicture = new user_picture($student);
 137      $usrepicture->courseid = $attemptobj->get_courseid();
 138      $summarydata['user'] = array(
 139          'title'   => $usrepicture,
 140          'content' => new action_link(new moodle_url('/user/view.php', array(
 141                                  'id' => $student->id, 'course' => $attemptobj->get_courseid())),
 142                            fullname($student, true)),
 143      );
 144  }
 145  
 146  if ($attemptobj->has_capability('mod/quiz:viewreports')) {
 147      $attemptlist = $attemptobj->links_to_other_attempts($attemptobj->review_url(null, $page,
 148              $showall));
 149      if ($attemptlist) {
 150          $summarydata['attemptlist'] = array(
 151              'title'   => get_string('attempts', 'quiz'),
 152              'content' => $attemptlist,
 153          );
 154      }
 155  }
 156  
 157  // Timing information.
 158  $summarydata['startedon'] = array(
 159      'title'   => get_string('startedon', 'quiz'),
 160      'content' => userdate($attempt->timestart),
 161  );
 162  
 163  $summarydata['state'] = array(
 164      'title'   => get_string('attemptstate', 'quiz'),
 165      'content' => quiz_attempt::state_name($attempt->state),
 166  );
 167  
 168  if ($attempt->state == quiz_attempt::FINISHED) {
 169      $summarydata['completedon'] = array(
 170          'title'   => get_string('completedon', 'quiz'),
 171          'content' => userdate($attempt->timefinish),
 172      );
 173      $summarydata['timetaken'] = array(
 174          'title'   => get_string('timetaken', 'quiz'),
 175          'content' => $timetaken,
 176      );
 177  }
 178  
 179  if (!empty($overtime)) {
 180      $summarydata['overdue'] = array(
 181          'title'   => get_string('overdue', 'quiz'),
 182          'content' => $overtime,
 183      );
 184  }
 185  
 186  // Show marks (if the user is allowed to see marks at the moment).
 187  $grade = quiz_rescale_grade($attempt->sumgrades, $quiz, false);
 188  if ($options->marks >= question_display_options::MARK_AND_MAX && quiz_has_grades($quiz)) {
 189  
 190      if ($attempt->state != quiz_attempt::FINISHED) {
 191          // Cannot display grade.
 192  
 193      } else if (is_null($grade)) {
 194          $summarydata['grade'] = array(
 195              'title'   => get_string('grade', 'quiz'),
 196              'content' => quiz_format_grade($quiz, $grade),
 197          );
 198  
 199      } else {
 200          // Show raw marks only if they are different from the grade (like on the view page).
 201          if ($quiz->grade != $quiz->sumgrades) {
 202              $a = new stdClass();
 203              $a->grade = quiz_format_grade($quiz, $attempt->sumgrades);
 204              $a->maxgrade = quiz_format_grade($quiz, $quiz->sumgrades);
 205              $summarydata['marks'] = array(
 206                  'title'   => get_string('marks', 'quiz'),
 207                  'content' => get_string('outofshort', 'quiz', $a),
 208              );
 209          }
 210  
 211          // Now the scaled grade.
 212          $a = new stdClass();
 213          $a->grade = html_writer::tag('b', quiz_format_grade($quiz, $grade));
 214          $a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
 215          if ($quiz->grade != 100) {
 216              $a->percent = html_writer::tag('b', format_float(
 217                      $attempt->sumgrades * 100 / $quiz->sumgrades, 0));
 218              $formattedgrade = get_string('outofpercent', 'quiz', $a);
 219          } else {
 220              $formattedgrade = get_string('outof', 'quiz', $a);
 221          }
 222          $summarydata['grade'] = array(
 223              'title'   => get_string('grade', 'quiz'),
 224              'content' => $formattedgrade,
 225          );
 226      }
 227  }
 228  
 229  // Any additional summary data from the behaviour.
 230  $summarydata = array_merge($summarydata, $attemptobj->get_additional_summary_data($options));
 231  
 232  // Feedback if there is any, and the user is allowed to see it now.
 233  $feedback = $attemptobj->get_overall_feedback($grade);
 234  if ($options->overallfeedback && $feedback) {
 235      $summarydata['feedback'] = array(
 236          'title'   => get_string('feedback', 'quiz'),
 237          'content' => $feedback,
 238      );
 239  }
 240  
 241  // Summary table end. ==============================================================================
 242  
 243  if ($showall) {
 244      $slots = $attemptobj->get_slots();
 245      $lastpage = true;
 246  } else {
 247      $slots = $attemptobj->get_slots($page);
 248      $lastpage = $attemptobj->is_last_page($page);
 249  }
 250  
 251  $output = $PAGE->get_renderer('mod_quiz');
 252  
 253  // Arrange for the navigation to be displayed.
 254  $navbc = $attemptobj->get_navigation_panel($output, 'quiz_review_nav_panel', $page, $showall);
 255  $regions = $PAGE->blocks->get_regions();
 256  $PAGE->blocks->add_fake_block($navbc, reset($regions));
 257  
 258  echo $output->review_page($attemptobj, $slots, $page, $showall, $lastpage, $options, $summarydata);
 259  
 260  // Trigger an event for this review.
 261  $params = array(
 262      'objectid' => $attemptobj->get_attemptid(),
 263      'relateduserid' => $attemptobj->get_userid(),
 264      'courseid' => $attemptobj->get_courseid(),
 265      'context' => context_module::instance($attemptobj->get_cmid()),
 266      'other' => array(
 267          'quizid' => $attemptobj->get_quizid()
 268      )
 269  );
 270  $event = \mod_quiz\event\attempt_reviewed::create($params);
 271  $event->add_record_snapshot('quiz_attempts', $attemptobj->get_attempt());
 272  $event->trigger();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1