I want to run a function when this button is clicked and the course module is deleted.
How can I do this?
I want to run a function when this button is clicked and the course module is deleted.
How can I do this?
I've added these and nothing happens. It works when I add \core\event\course_module_updated though I have no idea why. I need the \core\event\course_module_deleted event.
In db/events.php:
$observers = array(
array(
'eventname' => '\core\event\course_module_deleted',
'callback' => 'mod_game_observer::course_module_deleted',
),
);
In classes/observer.php:
defined('MOODLE_INTERNAL') || die();
class mod_game_observer {
/**
* Observer for the even course_module_deleted.
*
* @param \core\event\course_module_deleted $event
*/
public static function course_module_deleted(\core\event\course_module_deleted $event) {
global $DB;
//die(var_dump($event));
$DB->delete_records_select("game_results", "cmid = ".$event->objectid);
$DB->delete_records_select("game", "id = ".$event->other['instanceid']);
}
}