Search This Blog

Wednesday, December 19, 2012

Stop the navigation block from expanding


If you want to stop the navigation from automatically expanding everything you click a course, this is the code you need to change:

1) Go to:  blocks\navigation in your root moddle directory
2)  open renderer.php file
and change this line
if ($item->has_children() && (!$item->forceopen || $item->collapse)) {
to this
if ($item->has_children() && ($depth > 1)) {


Thursday, December 13, 2012

Only show block to certain user

I wanted to hide my "Settings" block from all other users, except the admin role.

1)  I went into the file called:  mymoodleroot/blocks/settings/block_settings.php
2)  Inside two functions, I simply placed a role check at the beginning:

 function get_content() 
 {
    // only shows the settings block to admins
    global $USER, $CFG, $DB;
    if(!is_siteadmin($USER)) {return;}
        ...
}


function init() 
    {
    global $USER, $CFG, $DB;
    if(!is_siteadmin($USER)) {return;}

      ...
}



I'm sure that code could be modified to display to different roles and possibilities. This is just a simple example and it works!