From 599a52fec7dabafc166908edf34621d7453603f7 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Sun, 22 Apr 2012 10:57:41 +0800 Subject: [PATCH] MDL-32508 course/view.php: moderise with MUST_EXIST --- course/view.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/course/view.php b/course/view.php index bc2fb37c758..7c39a1d2f4c 100644 --- a/course/view.php +++ b/course/view.php @@ -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)) { - print_error('unspecifycourseid', 'error'); - } - + $params = array(); if (!empty($name)) { - if (! ($course = $DB->get_record('course', array('shortname'=>$name)))) { - print_error('invalidcoursenameshort', 'error'); - } + $params = array('shortname' => $name); } 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'); - } + $params = array('idnumber' => $idnumber); + } else if (!empty($id)) { + $params = array('id' => $id); + }else { + print_error('unspecifycourseid', '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()) { -- 2.43.0