rating MDL-24513 made scales.php work with site level (not course level) scales
authorAndrew Davis <andrew@affinitysoftware.net>
Mon, 11 Oct 2010 06:21:53 +0000 (06:21 +0000)
committerAndrew Davis <andrew@affinitysoftware.net>
Mon, 11 Oct 2010 06:21:53 +0000 (06:21 +0000)
course/scales.php

index b4ca819..07bf4fa 100644 (file)
@@ -36,12 +36,17 @@ if ($scaleid !== 0) {
 }
 $PAGE->set_url($url);
 
-if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error("invalidcourseid");
+$context = null;
+if ($course = $DB->get_record('course', array('id'=>$id))) {
+    require_login($course);
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
+} else {
+    //$id will be 0 for site level scales
+    require_login();
+    $context = get_context_instance(CONTEXT_SYSTEM);
 }
 
-require_login($course);
-$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$PAGE->set_context($context);
 require_capability('moodle/course:viewscales', $context);
 
 $strscales = get_string("scales");
@@ -49,7 +54,11 @@ $strcustomscales = get_string("scalescustom");
 $strstandardscales = get_string("scalesstandard");
 
 $PAGE->set_title($strscales);
-$PAGE->set_heading($course->fullname);
+if (!empty($course)) {
+    $PAGE->set_heading($course->fullname);
+} else {
+    $PAGE->set_heading($SITE->fullname);
+}
 echo $OUTPUT->header();
 
 if ($scaleid) {