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