mirror of
https://github.com/moodle/moodle.git
synced 2025-06-02 14:15:11 +02:00
MDL-32508 course/view.php: moderise with MUST_EXIST
This commit is contained in:
parent
3fe600aacf
commit
599a52fec7
@ -18,30 +18,23 @@
|
||||
$marker = optional_param('marker',-1 , PARAM_INT);
|
||||
$switchrole = optional_param('switchrole',-1, PARAM_INT);
|
||||
|
||||
if (empty($id) && empty($name) && empty($idnumber)) {
|
||||
$params = array();
|
||||
if (!empty($name)) {
|
||||
$params = array('shortname' => $name);
|
||||
} else if (!empty($idnumber)) {
|
||||
$params = array('idnumber' => $idnumber);
|
||||
} else if (!empty($id)) {
|
||||
$params = array('id' => $id);
|
||||
}else {
|
||||
print_error('unspecifycourseid', 'error');
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
if (! ($course = $DB->get_record('course', array('shortname'=>$name)))) {
|
||||
print_error('invalidcoursenameshort', 'error');
|
||||
}
|
||||
} else if (!empty($idnumber)) {
|
||||
if (! ($course = $DB->get_record('course', array('idnumber'=>$idnumber)))) {
|
||||
print_error('invalidcourseid', 'error');
|
||||
}
|
||||
} else {
|
||||
if (! ($course = $DB->get_record('course', array('id'=>$id)))) {
|
||||
print_error('invalidcourseid', 'error');
|
||||
}
|
||||
}
|
||||
$course = $DB->get_record('course', $params, '*', MUST_EXIST);
|
||||
|
||||
$PAGE->set_url('/course/view.php', array('id' => $course->id)); // Defined here to avoid notices on errors etc
|
||||
|
||||
preload_course_contexts($course->id);
|
||||
if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
|
||||
print_error('nocontext');
|
||||
}
|
||||
$context = context_course::instance($course->id, MUST_EXIST);
|
||||
|
||||
// Remove any switched roles before checking login
|
||||
if ($switchrole == 0 && confirm_sesskey()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user