diff --git a/course/format/formatlegacy.php b/course/format/formatlegacy.php index 61a5658392b5c..516f3c5f94a7c 100644 --- a/course/format/formatlegacy.php +++ b/course/format/formatlegacy.php @@ -178,4 +178,28 @@ function ajax_section_move() { return parent::ajax_section_move(); } } + + /** + * Returns the list of blocks to be automatically added for the newly created course + * + * This function checks the existence of the file config.php in the course format folder. + * If file exists and contains the code + * $format['defaultblocks'] = 'leftblock1,leftblock2:rightblock1,rightblock2'; + * these blocks are used, otherwise parent function is called + * + * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT + * each of values is an array of block names (for left and right side columns) + */ + public function get_default_blocks() { + global $CFG; + $formatconfig = $CFG->dirroot.'/course/format/'.$this->format.'/config.php'; + $format = array(); // initialize array in external file + if (is_readable($formatconfig)) { + include($formatconfig); + } + if (!empty($format['defaultblocks'])) { + return blocks_parse_default_blocks_list($format['defaultblocks']); + } + return parent::get_default_blocks(); + } } \ No newline at end of file diff --git a/course/format/lib.php b/course/format/lib.php index 7a0484cd7d0c2..9496601e9b420 100644 --- a/course/format/lib.php +++ b/course/format/lib.php @@ -391,6 +391,26 @@ public function extend_course_navigation(&$navigation, navigation_node $node) { } return array(); } + + /** + * Returns the list of blocks to be automatically added for the newly created course + * + * @see blocks_add_default_course_blocks() + * + * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT + * each of values is an array of block names (for left and right side columns) + */ + public function get_default_blocks() { + global $CFG; + if (!empty($CFG->defaultblocks)){ + return blocks_parse_default_blocks_list($CFG->defaultblocks); + } + $blocknames = array( + BLOCK_POS_LEFT => array(), + BLOCK_POS_RIGHT => array('search_forums', 'news_items', 'calendar_upcoming', 'recent_activity') + ); + return $blocknames; + } } /** diff --git a/lib/blocklib.php b/lib/blocklib.php index e9c133ffed6ec..66773d221a8f8 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -2105,30 +2105,12 @@ function blocks_add_default_course_blocks($course) { } else if ($course->id == SITEID) { $blocknames = blocks_get_default_site_course_blocks(); - } else { - $defaultblocks = 'defaultblocks_' . $course->format; - if (!empty($CFG->$defaultblocks)) { - $blocknames = blocks_parse_default_blocks_list($CFG->$defaultblocks); - - } else { - $formatconfig = $CFG->dirroot.'/course/format/'.$course->format.'/config.php'; - $format = array(); // initialize array in external file - if (is_readable($formatconfig)) { - include($formatconfig); - } - if (!empty($format['defaultblocks'])) { - $blocknames = blocks_parse_default_blocks_list($format['defaultblocks']); + } else if (!empty($CFG->{'defaultblocks_' . $course->format})) { + $blocknames = blocks_parse_default_blocks_list($CFG->{'defaultblocks_' . $course->format}); - } else if (!empty($CFG->defaultblocks)){ - $blocknames = blocks_parse_default_blocks_list($CFG->defaultblocks); + } else { + $blocknames = course_get_format($course)->get_default_blocks(); - } else { - $blocknames = array( - BLOCK_POS_LEFT => array(), - BLOCK_POS_RIGHT => array('search_forums', 'news_items', 'calendar_upcoming', 'recent_activity') - ); - } - } } if ($course->id == SITEID) {