(Programmatically) defining Dashboard default blocks

Re: (Programmatically) defining Dashboard default blocks

by Howard Miller -
Number of replies: 1
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Erm.... read Marina's comment smile

That bit worked as advertised (adding a block to the *default*) but I'm struggling to modify that  (if it's possible) to update *existing* dashboards. To be honest, I'm not entirely sure how that code works. 

In reply to Howard Miller

Re: (Programmatically) defining Dashboard default blocks

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Howard,
there are functions my_reset_page() and my_reset_page_for_all_users() that resets dashboards of one/all users.
Basically what it does is removing all users dashboards. Next time when user logs in after his dashboard was reset the dashboard is automatically created as a copy of the default calling function my_copy_page().

You can look at the code of these functions to get inspiration for your use case.

If you don't want to reset all users dashboards but just want to add a block to them, this is what you need to do:
1. add this block to the default dashboard
2. loop through all existing users dashboards:
SELECT id, userid FROM {my_pages} where private=1 and userid is not null
get the instance of the block from the default dashboard and copy it to all existing users' dashboards similar to what my_copy_page() is doing.
Average of ratings: Useful (2)