Tuesday 25 April 2017

Moodle: Block settings not shown for students

Hello,

If you want to disable (not shown) settings block for students in Moodle, you can do it changing the renderer in your theme. This code is valid only for themes not based on Boost.

Add this function in the core_renderer class of your theme:

public function block(block_contents $bc, $region) {
        global $DB;

        $idblock = isset($bc->attributes['id']) ? $bc->attributes['id'] : '';
        $arr_aux = explode('inst', $idblock);
        if (isset($arr_aux[1])) {
                $block_instance = $DB->get_record('block_instances', array('id' => $arr_aux[1]));
                $context_course = context_course::instance($this->page->course->id);
                if (isset($block_instance->blockname) && $block_instance->blockname == 'settings') {
                    if (!has_capability('moodle/grade:viewall', $context_course)) {
                        return '';
                    }
                }
        }

        return parent::block($bc, $region);
}

Best regards,
Iban Cardona.

No comments:

Post a Comment