[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/quiz/ -> report.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 script controls the display of the quiz reports.
  19   *
  20   * @package   mod_quiz
  21   * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  require_once(__DIR__ . '/../../config.php');
  27  require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  28  require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
  29  require_once($CFG->dirroot . '/mod/quiz/report/default.php');
  30  
  31  $id = optional_param('id', 0, PARAM_INT);
  32  $q = optional_param('q', 0, PARAM_INT);
  33  $mode = optional_param('mode', '', PARAM_ALPHA);
  34  
  35  if ($id) {
  36      if (!$cm = get_coursemodule_from_id('quiz', $id)) {
  37          print_error('invalidcoursemodule');
  38      }
  39      if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
  40          print_error('coursemisconf');
  41      }
  42      if (!$quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
  43          print_error('invalidcoursemodule');
  44      }
  45  
  46  } else {
  47      if (!$quiz = $DB->get_record('quiz', array('id' => $q))) {
  48          print_error('invalidquizid', 'quiz');
  49      }
  50      if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
  51          print_error('invalidcourseid');
  52      }
  53      if (!$cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
  54          print_error('invalidcoursemodule');
  55      }
  56  }
  57  
  58  $url = new moodle_url('/mod/quiz/report.php', array('id' => $cm->id));
  59  if ($mode !== '') {
  60      $url->param('mode', $mode);
  61  }
  62  $PAGE->set_url($url);
  63  
  64  require_login($course, false, $cm);
  65  $context = context_module::instance($cm->id);
  66  $PAGE->set_pagelayout('report');
  67  
  68  $reportlist = quiz_report_list($context);
  69  if (empty($reportlist)) {
  70      print_error('erroraccessingreport', 'quiz');
  71  }
  72  
  73  // Validate the requested report name.
  74  if ($mode == '') {
  75      // Default to first accessible report and redirect.
  76      $url->param('mode', reset($reportlist));
  77      redirect($url);
  78  } else if (!in_array($mode, $reportlist)) {
  79      print_error('erroraccessingreport', 'quiz');
  80  }
  81  if (!is_readable("report/$mode/report.php")) {
  82      print_error('reportnotfound', 'quiz', '', $mode);
  83  }
  84  
  85  // Open the selected quiz report and display it.
  86  $file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';
  87  if (is_readable($file)) {
  88      include_once($file);
  89  }
  90  $reportclassname = 'quiz_' . $mode . '_report';
  91  if (!class_exists($reportclassname)) {
  92      print_error('preprocesserror', 'quiz');
  93  }
  94  
  95  $report = new $reportclassname();
  96  $report->display($quiz, $cm, $course);
  97  
  98  // Print footer.
  99  echo $OUTPUT->footer();
 100  
 101  // Log that this report was viewed.
 102  $params = array(
 103      'context' => $context,
 104      'other' => array(
 105          'quizid' => $quiz->id,
 106          'reportname' => $mode
 107      )
 108  );
 109  $event = \mod_quiz\event\report_viewed::create($params);
 110  $event->add_record_snapshot('course', $course);
 111  $event->add_record_snapshot('quiz', $quiz);
 112  $event->trigger();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1