Get course id from inside block object

Get course id from inside block object

by Björn Bergstrand -
Number of replies: 1

I'm writing a cron-function for a specialized block and I need to be able to access which course this block instance is created in.

I get the instances running

$instances = $DB->get_records( 'block_instances', array('blockname'=>'myblock') );

then iterating over them as $instance, getting the block_base object and finally the information I need will be in _instanceid in the context_course object

$block = block_instance('myblock', $instance);

context::instance_by_id($block->instance->parentcontextid);


I cannot figure out how to get at that _instanceid, could someone help me out here?

Average of ratings: -
In reply to Björn Bergstrand

Re: Get course id from inside block object

by Björn Bergstrand -

Just braindamage on my part, you can actually access it directly ( ->instanceid ). I was fooled by the leading underscore in the documentation.