Browse files

Added new default block definition functionality.

  • Loading branch information...
1 parent b18a962 commit 25d18413cf04a0f4c679f0b089eedb06a7642115 mchurch committed Sep 3, 2004
Showing with 47 additions and 16 deletions.
  1. +1 −6 course/edit.php
  2. +46 −10 lib/blocklib.php
View
7 course/edit.php
@@ -69,12 +69,7 @@
$form->timecreated = time();
//Create blockinfo default content
- if ($form->format == "social") {
- $form->blockinfo = blocks_get_default_blocks (NULL,"participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,admin,course_list");
- } else {
- //For topics and weeks formats (default built in the function)
- $form->blockinfo = blocks_get_default_blocks();
- }
+ $form->blockinfo = blocks_get_default_blocks(null, blocks_get_config_default($form->format));
if ($newcourseid = insert_record("course", $form)) { // Set up new course
$section = NULL;
View
56 lib/blocklib.php
@@ -9,11 +9,6 @@
define('BLOCK_MOVE_UP', 0x04);
define('BLOCK_MOVE_DOWN', 0x08);
-define('BLOCKS_DEFAULT_SITE', 'site_main_menu,admin,course_list:course_summary,calendar_month');
-define('BLOCKS_DEFAULT_SOCIAL', 'participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,admin,course_list');
-define('BLOCKS_DEFAULT_TOPICS', 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity');
-define('BLOCKS_DEFAULT_WEEKS', 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity');
-
function block_remove_inappropriate_from_course(&$course) {
$blocks = $course->blockinfo;
@@ -679,7 +674,8 @@ function upgrade_blocks_plugins($continueto) {
if ($courses = get_records("course")) {
foreach ($courses as $course) {
//Depending of the format, insert some values
- $blockinfo = blocks_get_default_blocks ($course->id, constant('BLOCKS_DEFAULT_'.strtoupper($course->format)));
+ $blockinfo = blocks_get_default_blocks ($course->id,
+ blocks_get_config_default($course->format));
if ($CFG->debug) {
echo 'Updating blockinfo for course: '.$course->shortname.'('.$blockinfo.')<br>';
}
@@ -688,7 +684,7 @@ function upgrade_blocks_plugins($continueto) {
}
if (!empty($CFG->siteblocksadded)) { /// This is a once-off hack to make a proper upgrade
- blocks_get_default_blocks(SITEID, BLOCKS_DEFAULT_SITE); // Add blockinfo to the site course
+ blocks_get_default_blocks(SITEID, blocks_get_config_default()); // Add blockinfo to the site course
delete_records('config', 'name', 'siteblocksadded');
}
@@ -825,10 +821,10 @@ function blocks_get_default_blocks ($courseid = NULL, $blocknames = '') {
global $CFG;
if (empty($blocknames)) {
- if (!empty($CFG->defaultblocks)) {
- $blocknames = $CFG->defaultblocks;
+ if (!empty($CFG->defaultblocks_override)) {
+ $blocknames = $CFG->defaultblocks_override;
} else {
- $blocknames = BLOCKS_DEFAULT_WEEKS;
+ $blocknames = $CFG->defaultblocks;
}
}
@@ -917,6 +913,46 @@ function blocks_get_default_blocks ($courseid = NULL, $blocknames = '') {
return $blockinfo;
}
+// This function returns the appropriate block default configuration string
+// according to the $format argument. It will return the site override defined
+// in the site config, a format override defined in the site config, a specific
+// config defined in the course format config, or the site default.
+// To request the site format, leave $format blank.
+function blocks_get_config_default ($cformat='') {
+
+ global $CFG;
+
+ /// If the site override has been defined, it is the only valid one.
+ if (!empty($CFG->defaultblocks_override)) {
+ return $CFG->defaultblocks_override;
+ }
+ /// If not format is specified, return the site default.
+ else if ($cformat == '') {
+ if (!empty($CFG->defaultblocks_site)) {
+ return $CFG->defaultblocks_site;
+ }
+ else {
+ return $CFG->defaultblocks;
+ }
+ }
+ /// Return the appropriate block string for the format.
+ else if (!empty($CFG->{'defaultblocks_'.$cformat})) {
+ return $CFG->{'defaultblocks_'.$cformat};
+ }
+ else {
+ $format_config = $CFG->dirroot.'/course/format/'.$cformat.'/config.php';
+ if (file_exists($format_config)) {
+ require($format_config);
+ }
+ if (!empty($format['defaultblocks'])) {
+ return $format['defaultblocks'];
+ }
+ else {
+ return $CFG->defaultblocks;
+ }
+ }
+}
+
//This function will return the names representation of the blockinfo field.
//It's used to include that info in backups. To restore we'll use the
//blocks_get_block_ids() function. It makes the opposite conversion

0 comments on commit 25d1841

Please sign in to comment.