Skip to content

Commit

Permalink
MDL-37206 preload course format renderer in course/view.php
Browse files Browse the repository at this point in the history
Also fixed bug with hardcoded default 'weeks' format
  • Loading branch information
marinaglancy committed Jan 14, 2013
1 parent ca48fe5 commit 8afb1cc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions course/view.php
Expand Up @@ -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);
Expand Down

0 comments on commit 8afb1cc

Please sign in to comment.