From c069dacfc1baff8ff272c2e975245ce2ce4014b2 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 21 Jun 2012 16:24:40 +0100 Subject: [PATCH] MDL-33937 Paged course view: Allows view of sections that are not visible --- course/view.php | 14 ++++++++++++-- lib/modinfolib.php | 12 ++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/course/view.php b/course/view.php index e4a18cda2d3..ad495dd7a85 100644 --- a/course/view.php +++ b/course/view.php @@ -99,8 +99,18 @@ $infoid = $course->id; if(!empty($section)) { $loglabel = 'view section'; - $sectionparams = array('course' => $course->id, 'section' => $section); - $coursesections = $DB->get_record('course_sections', $sectionparams, 'id', MUST_EXIST); + + // Get section details and check it exists. + $modinfo = get_fast_modinfo($course); + $coursesections = $modinfo->get_section_info($section, MUST_EXIST); + + // Check user is allowed to see it. + if (!$coursesections->uservisible) { + // Note: We actually already know they don't have this capability + // or uservisible would have been true; this is just to get the + // correct error message shown. + require_capability('moodle/course:viewhiddensections', $context); + } $infoid = $coursesections->id; $logparam .= '§ionid='. $infoid; } diff --git a/lib/modinfolib.php b/lib/modinfolib.php index bcbb7ecff22..f22f6979f54 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -202,9 +202,17 @@ class course_modinfo extends stdClass { /** * Gets data about specific numbered section. * @param int $sectionnumber Number (not id) of section - * @return section_info Information for numbered section + * @param int $strictness Use MUST_EXIST to throw exception if it doesn't + * @return section_info Information for numbered section or null if not found */ - public function get_section_info($sectionnumber) { + public function get_section_info($sectionnumber, $strictness = IGNORE_MISSING) { + if (!array_key_exists($sectionnumber, $this->sectioninfo)) { + if ($strictness === MUST_EXIST) { + throw new moodle_exception('sectionnotexist'); + } else { + return null; + } + } return $this->sectioninfo[$sectionnumber]; }