Setting of default block layout in 1.5

Setting of default block layout in 1.5

by Julian Ridden -
Number of replies: 6

I am soon to launch our Moodle 1.5 into our school environment and want to reset all blocks in our courses to a standard layout before my teachers go nuts customising.

My question is: How can I define my block layouts in all courses at once?

I do not want to have to go through each course manually to do so.

If the only means to do this is through an SQL edit, can you please inform me which table it is I will need to edit.

Thanks

Average of ratings: -
In reply to Julian Ridden

Re: Setting of default block layout in 1.5

by John Papaioannou -
Hi Julian,

You can't really do it "easily" without getting your hands a bit dirty with code. With code, it's a snap. Now, I 'm going to provide a tiny script that does what you want, but please remember to backup your database first etc etc so that you don't shoot yourself in the foot if something goes wrong. Not that it will, but you know, just being cautious. wink

Now for the code: just copy and paste this into a .php file in your Moodle root directory (the same directory where config.php is). Let's assume you call this file "resetblocks.php". Simply go into your browser, visit http://your.site.here/moodle/resetblocks.php and it should all return to defaults.

Remember to remove this .php file afterwards; you don't want anyone else to do it when your site is operating!

The code is:

<?php

require_once('config.php');
require_once($CFG->libdir.'/blocklib.php');

$courses = get_records('course');

foreach($courses as $course) {
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
blocks_repopulate_page($page);
}

print_heading('Done!');

?>

In reply to John Papaioannou

Re: Setting of default block layout in 1.5

by Ger Tielemans -

Jon, is it easy to change this script, so you can:

  1. show an overview of the blocks for all the courses
    (in 1.4 this was visible in one database field)
  2. checkmark the courses where you want to change the blocks
  3. set the change by hand (like under 1.4) or use your script.
    (maybe choose from different sets in the config, like default,week,topic)
In reply to Ger Tielemans

Re: Setting of default block layout in 1.5

by John Papaioannou -
It wouldn't be too difficult Ger, but unfortunately these days I don't have the time to do it... mixed
In reply to Julian Ridden

Re: Setting of default block layout in 1.5

by Daryl Hawes -
Julian,
  Jon's answer will help if you want to reset existing courses back to their default block settings. If instead you are looking for new courses to automatically have different default blocks than those that moodle provides you can edit your config.php file. These examples are found in the config-dist.php file:

// These variables define DEFAULT block variables for new courses
// If this one is set it overrides all others and is the only one used.
//      $CFG->defaultblocks_override = 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
//
// These variables define the specific settings for defined course formats.
// They override any settings defined in the formats own config file.
//      $CFG->defaultblocks_site = 'site_main_menu,admin,course_list:course_summary,calendar_month';
//      $CFG->defaultblocks_social = 'participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,admin,course_list';
//      $CFG->defaultblocks_topics = 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
//      $CFG->defaultblocks_weeks = 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
// These blocks are used when no other default setting is found.
//      $CFG->defaultblocks = 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';


So copy one of the above lines to your config file, remove the comment from the beginning of the line, and customize the block names as needed.
In reply to Daryl Hawes

Re: Setting of default block layout in 1.5

by John Papaioannou -
Yes, it now looks like I didn't quite understand what you asked for, Julian.

Anyway, if you already have the courses created and do not want to create them all over again, but still want to change the blocks in all of them, you can combine our solutions. First do Daryl's, and then do mine. This will "reset" all course blocks using the defaults you just provided.
In reply to John Papaioannou

Re: Setting of default block layout in 1.5

by Julian Ridden -

Many thanks to both of you. You hit the nail on the head with that one.

I looked everywhere for that setting Daryl, but of course my config file is a really old extremely simple version with no addition features code. Thanks for the heads up

Would be good to see some kind of basic GUI interface to this (even if it isjust a filed where you type in block names for now) in the Blocks admin allowing you to reset blocks as we have just done.

As expected the script ran flawlessly (although it was only small) :D

*bows down and prays to Jon and his Moodle scripting*  We're not worthy, we're not worth

smile