Permalink
Browse files

MDL-37206 preload course format renderer in course/view.php

Also fixed bug with hardcoded default 'weeks' format
  • Loading branch information...
marinaglancy authored and Sam Hemelryk committed Jan 11, 2013
1 parent 2dcbaaa commit f939cf3159fb2aefa71b30f6765388d0b230f850
Showing with 14 additions and 4 deletions.
  1. +14 −4 course/view.php
View
@@ -117,15 +117,25 @@
}
add_to_log($course->id, 'course', $loglabel, "view.php?". $logparam, $infoid);
- $course->format = clean_param($course->format, PARAM_ALPHA);
- if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) {
- $course->format = 'weeks'; // Default format is weeks
- }
+ // Fix course format if it is no longer installed
+ $course->format = course_get_format($course)->get_format();
$PAGE->set_pagelayout('course');
$PAGE->set_pagetype('course-view-' . $course->format);
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
+ // Preload course format renderer before output starts.
+ // This is a little hacky but necessary since
+ // format.php is not included until after output starts
+ if (file_exists($CFG->dirroot.'/course/format/'.$course->format.'/renderer.php')) {
+ require_once($CFG->dirroot.'/course/format/'.$course->format.'/renderer.php');
+ if (class_exists('format_'.$course->format.'_renderer')) {
+ // call get_renderer only if renderer is defined in format plugin
+ // otherwise an exception would be thrown
+ $PAGE->get_renderer('format_'. $course->format);
+ }
+ }
+
if ($reset_user_allowed_editing) {
// ugly hack
unset($PAGE->_user_allowed_editing);

0 comments on commit f939cf3

Please sign in to comment.