2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2007-07-23 22:20:07 +00:00
|
|
|
|
2012-01-06 11:52:46 +07:00
|
|
|
/**
|
|
|
|
* Redirects the user to the default grade report
|
|
|
|
*
|
|
|
|
* @package core_grades
|
|
|
|
* @copyright 2007 Petr Skoda
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2009-03-17 10:52:27 +00:00
|
|
|
require_once '../../config.php';
|
2007-07-23 22:20:07 +00:00
|
|
|
|
|
|
|
$courseid = required_param('id', PARAM_INT);
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/grade/report/index.php', array('id'=>$courseid));
|
2009-10-15 06:58:21 +00:00
|
|
|
|
2007-07-23 22:20:07 +00:00
|
|
|
/// basic access checks
|
2008-06-03 16:10:57 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
2007-07-23 22:20:07 +00:00
|
|
|
print_error('nocourseid');
|
|
|
|
}
|
|
|
|
require_login($course);
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2007-07-23 22:20:07 +00:00
|
|
|
|
|
|
|
/// find all accessible reports
|
2013-07-16 22:36:11 +02:00
|
|
|
$reports = core_component::get_plugin_list('gradereport'); // Get all installed reports
|
2009-06-19 14:25:56 +00:00
|
|
|
|
|
|
|
foreach ($reports as $plugin => $plugindir) { // Remove ones we can't see
|
|
|
|
if (!has_capability('gradereport/'.$plugin.':view', $context)) {
|
2009-09-26 18:22:12 +00:00
|
|
|
unset($reports[$plugin]);
|
2007-07-23 22:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($reports)) {
|
2011-09-16 12:00:19 +01:00
|
|
|
print_error('noreports', 'debug', $CFG->wwwroot.'/course/view.php?id='.$course->id);
|
2007-07-23 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($USER->grade_last_report)) {
|
|
|
|
$USER->grade_last_report = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($USER->grade_last_report[$course->id])) {
|
|
|
|
$last = $USER->grade_last_report[$course->id];
|
|
|
|
} else {
|
|
|
|
$last = null;
|
|
|
|
}
|
|
|
|
|
2009-07-06 06:56:25 +00:00
|
|
|
if (!array_key_exists($last, $reports)) {
|
2007-07-23 22:20:07 +00:00
|
|
|
$last = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($last)) {
|
2009-07-06 06:56:25 +00:00
|
|
|
if (array_key_exists('grader', $reports)) {
|
2007-07-23 22:20:07 +00:00
|
|
|
$last = 'grader';
|
|
|
|
|
2011-09-16 12:00:19 +01:00
|
|
|
} else if (array_key_exists($CFG->grade_profilereport, $reports)) {
|
|
|
|
$last = $CFG->grade_profilereport;
|
2007-07-24 07:45:15 +00:00
|
|
|
|
2007-07-23 22:20:07 +00:00
|
|
|
} else {
|
2011-09-16 12:00:19 +01:00
|
|
|
reset($reports);
|
|
|
|
$last = key($reports);
|
2007-07-23 22:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//redirect to last or guessed report
|
|
|
|
redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id);
|
|
|
|
|