Add a Block to course from

Add a Block to course from

by A. Obeid -
Number of replies: 3

Hi,

is there a way to add a Block to a course via Web services or Api?

Moodle 2.8

Thanks

Average of ratings: -
In reply to A. Obeid

Re: Add a Block to course from

by Kathir Rajaraman -

Hi Obeld

I this add block a course via webservice not option there. So we customize the code for PHP code. You accombish the following code


$context = get_context_instance(CONTEXT_COURSE, 'Courseid');


$contextid = $context->id;
$record
= new stdClass();
$record->id = '';
$record->blockname = 'block name';

$record->parentcontextid = $contextid;
$record->showinsubcontexts = '0';
$record->pagetypepattern = 'course-view-*';
$record->subpagepattern = '';
$record->defaultregion = 'side-pre';
$record->defaultweight = '2';
$record->configdata = '';
$lastinsertid = $DB->insert_record('block_instances', $record, false);

This code what ever you need put this code and change course id.

Thanks

Kathir R