mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-35769 Course formats: Added function format_base::default_blocks() to replace format config.php
This commit is contained in:
parent
ecfe814e0f
commit
a49e2ea7e6
3 changed files with 48 additions and 22 deletions
|
@ -178,4 +178,28 @@ class format_legacy extends format_base {
|
||||||
return parent::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();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -391,6 +391,26 @@ abstract class format_base {
|
||||||
}
|
}
|
||||||
return array();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2105,30 +2105,12 @@ function blocks_add_default_course_blocks($course) {
|
||||||
} else if ($course->id == SITEID) {
|
} else if ($course->id == SITEID) {
|
||||||
$blocknames = blocks_get_default_site_course_blocks();
|
$blocknames = blocks_get_default_site_course_blocks();
|
||||||
|
|
||||||
|
} else if (!empty($CFG->{'defaultblocks_' . $course->format})) {
|
||||||
|
$blocknames = blocks_parse_default_blocks_list($CFG->{'defaultblocks_' . $course->format});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$defaultblocks = 'defaultblocks_' . $course->format;
|
$blocknames = course_get_format($course)->get_default_blocks();
|
||||||
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)){
|
|
||||||
$blocknames = blocks_parse_default_blocks_list($CFG->defaultblocks);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$blocknames = array(
|
|
||||||
BLOCK_POS_LEFT => array(),
|
|
||||||
BLOCK_POS_RIGHT => array('search_forums', 'news_items', 'calendar_upcoming', 'recent_activity')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($course->id == SITEID) {
|
if ($course->id == SITEID) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue