Set placement of default blocks (2.3.2)

Set placement of default blocks (2.3.2)

by Richard Crawford -
Number of replies: 2

We're using Moodle 2.3.2. We're not able to upgrade because of code customizing (but at least we've migrated off 1.9!).

We have a script on our server that will create a course in Moodle on demand. So far the script works great; the modules are placed appropriately and function, the students are enrolled properly, and so on.

The part I'm having a problem with is setting the default settings of the blocks in these courses. I know how to update the config.php file to set default blocks for my courses:

$CFG->defaultblocks = 'navigation,online_users,jmail,activity_modules,settings';

That part's working like a charm, but the blocks are not showing up in the course "subpages", such as the participants list or the forum pages. The block settings show that the blocks are set to show up on "Any type of course main page"; is there an easy way to set it to "Any course page" by default when creating a course?

As always, I'm not afraid to mess around with PHP or my database if that becomes necessary.

Average of ratings: -
In reply to Richard Crawford

Re: Set placement of default blocks (2.3.2)

by Richard Crawford -

Got it. I added the following lines to my script:

$courseblocks = $DB->get_records("block_instances",array("parentcontextid" => $coursecontextid));
foreach ($courseblocks as $block) {
    $blockupdate = new stdClass();
    $blockupdate->id = $block->id;
    $blockupdate->showinsubcontexts = 1;
    $blockupdate->pagetypepattern = '*';
}

It's working now.

In reply to Richard Crawford

Re: Set placement of default blocks (2.3.2)

by Jeremy Morrison -

I too am trying to accomplish this.

Whereabouts in your code are you placing this?