Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

   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   * Base class for quiz report plugins.
  19   *
  20   * @package   mod_quiz
  21   * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  
  29  /**
  30   * Base class for quiz report plugins.
  31   *
  32   * Doesn't do anything on it's own -- it needs to be extended.
  33   * This class displays quiz reports.  Because it is called from
  34   * within /mod/quiz/report.php you can assume that the page header
  35   * and footer are taken care of.
  36   *
  37   * This file can refer to itself as report.php to pass variables
  38   * to itself - all these will also be globally available.  You must
  39   * pass "id=$cm->id" or q=$quiz->id", and "mode=reportname".
  40   *
  41   * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
  42   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  abstract class quiz_default_report {
  45      const NO_GROUPS_ALLOWED = -2;
  46  
  47      /**
  48       * Override this function to displays the report.
  49       * @param $cm the course-module for this quiz.
  50       * @param $course the coures we are in.
  51       * @param $quiz this quiz.
  52       */
  53      public abstract function display($cm, $course, $quiz);
  54  
  55      /**
  56       * Initialise some parts of $PAGE and start output.
  57       *
  58       * @param object $cm the course_module information.
  59       * @param object $coures the course settings.
  60       * @param object $quiz the quiz settings.
  61       * @param string $reportmode the report name.
  62       */
  63      public function print_header_and_tabs($cm, $course, $quiz, $reportmode = 'overview') {
  64          global $PAGE, $OUTPUT, $CFG;
  65  
  66          // Print the page header.
  67          $PAGE->set_title($quiz->name);
  68          $PAGE->set_heading($course->fullname);
  69          echo $OUTPUT->header();
  70          $context = context_module::instance($cm->id);
  71          if (!$PAGE->has_secondary_navigation()) {
  72              echo $OUTPUT->heading(format_string($quiz->name, true, array('context' => $context)));
  73          }
  74          if (!empty($CFG->enableplagiarism)) {
  75              require_once($CFG->libdir . '/plagiarismlib.php');
  76              echo plagiarism_update_status($course, $cm);
  77          }
  78      }
  79  
  80      /**
  81       * Get the current group for the user user looking at the report.
  82       *
  83       * @param object $cm the course_module information.
  84       * @param object $coures the course settings.
  85       * @param context $context the quiz context.
  86       * @return int the current group id, if applicable. 0 for all users,
  87       *      NO_GROUPS_ALLOWED if the user cannot see any group.
  88       */
  89      public function get_current_group($cm, $course, $context) {
  90          $groupmode = groups_get_activity_groupmode($cm, $course);
  91          $currentgroup = groups_get_activity_group($cm, true);
  92  
  93          if ($groupmode == SEPARATEGROUPS && !$currentgroup && !has_capability('moodle/site:accessallgroups', $context)) {
  94              $currentgroup = self::NO_GROUPS_ALLOWED;
  95          }
  96  
  97          return $currentgroup;
  98      }
  99  }