How to reload course view page from event observer

How to reload course view page from event observer

by Zoran Jeremic -
Number of replies: 2
Hi,

I've implemented moodle activity that automatically creates chat and discussion forum on its creation. When activity is deleted these two are deleted from event observers that handle course_module_deleted event. The problem is that these two deleted activities are still visible until page is reloaded, and I don't know how to reload it from the observer. I tried redirect and header, but it doesn't work from observer.

I hope someone has some idea how to fix this.

Thanks,
Zoran


Average of ratings: -
In reply to Zoran Jeremic

Re: How to reload course view page from event observer

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

A local plugin can hook into the navigation update by creating (in lib.php) a function called local_NAMEOFPLUGIN_extend_settings_navigation().

You could use that to inject some javascript into the page, you could try watching for an activity being deleted then refresh the page - but that may involve a lot of polling of the server to see if the refresh is needed.

The only other solution that springs to mind would involve hacking the core 'delete activity' code, to fire off a query after the delete is finished, to see if the page should be reloaded.

In reply to Davo Smith

Re: How to reload course view page from event observer

by Zoran Jeremic -

Hi Davo,

Thank you for your suggestion. Changing the core code is not an option for me, and for the other solution with javascript that will poll and check if something was deleted on the course page it would probably work, but as you already stated it would be very inefficient to have javacode polling all the time for such situations which rarely happens.

Zoran