Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
/**
18
 * Redirects the user to the default grade report
19
 *
20
 * @package   core_grades
21
 * @copyright 2007 Petr Skoda
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once '../../config.php';
26
 
27
$courseid = required_param('id', PARAM_INT);
28
 
29
$PAGE->set_url('/grade/report/index.php', array('id'=>$courseid));
30
 
31
/// basic access checks
32
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
33
    throw new \moodle_exception('invalidcourseid');
34
}
35
require_login($course);
36
$context = context_course::instance($course->id);
37
 
38
/// find all accessible reports
39
$reports = core_component::get_plugin_list('gradereport');     // Get all installed reports
40
 
41
foreach ($reports as $plugin => $plugindir) {                      // Remove ones we can't see
42
    if (!has_capability('gradereport/'.$plugin.':view', $context)) {
43
        unset($reports[$plugin]);
44
    }
45
}
46
 
47
if (empty($reports)) {
48
    throw new \moodle_exception('noreports', 'debug', $CFG->wwwroot.'/course/view.php?id='.$course->id);
49
}
50
 
51
if (!isset($USER->grade_last_report)) {
52
    $USER->grade_last_report = array();
53
}
54
 
55
if (!empty($USER->grade_last_report[$course->id])) {
56
    $last = $USER->grade_last_report[$course->id];
57
} else {
58
    $last = null;
59
}
60
 
61
if (!array_key_exists($last, $reports)) {
62
    $last = null;
63
}
64
 
65
if (empty($last)) {
66
    if (array_key_exists('grader', $reports)) {
67
        $last = 'grader';
68
 
69
    } else if (array_key_exists($CFG->grade_profilereport, $reports)) {
70
        $last = $CFG->grade_profilereport;
71
 
72
    } else {
73
        reset($reports);
74
        $last = key($reports);
75
    }
76
}
77
 
78
//redirect to last or guessed report
79
redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id);
80