Skip to content

Commit

Permalink
MDL-35769 Course formats: Added function format_base::default_blocks(…
Browse files Browse the repository at this point in the history
…) to replace format config.php
  • Loading branch information
marinaglancy committed Oct 15, 2012
1 parent ecfe814 commit a49e2ea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
24 changes: 24 additions & 0 deletions course/format/formatlegacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
20 changes: 20 additions & 0 deletions course/format/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
26 changes: 4 additions & 22 deletions lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a49e2ea

Please sign in to comment.