Add a block to each course - NOT via the front page

Re: Add a block to each course - NOT via the front page

by Brian Merritt -
Number of replies: 0
Picture of Particularly helpful Moodlers

If it's any help, I did an SQL query that pulls in all courses, and then if the blocks.id and blocks.blockname are null then that course needs to have the block added (the left join takes care of that)

SELECT DISTINCT course.id, course.shortname, course.fullname, blocks.id , blocks.blockname, blocks.parentcontextid  FROM database_name_here.mdl_course as course
	inner join moodle_2015.mdl_context as context
    on context.instanceid = course.id
	left join moodle_2015.mdl_block_instances as blocks
    on blocks.blockname = "choose_name_of_block"
       AND context.id = blocks.parentcontextid ;

Note this is pure SQL, if using Moodle to query it will be slightly different

Just update the database name and the name of the block to get the results