diff --git a/db/events.php b/db/events.php new file mode 100644 index 0000000..3ed930f --- /dev/null +++ b/db/events.php @@ -0,0 +1,5 @@ + + + + +`; + + // Append the modal HTML to the document body + document.body.insertAdjacentHTML('beforeend', modalHTML); + // Function to load a script into the DOM function loadScript(url, integrity, crossorigin) { return new Promise((resolve, reject) => { diff --git a/lib.php b/lib.php index 6ed97d7..da71247 100644 --- a/lib.php +++ b/lib.php @@ -56,3 +56,44 @@ function mod_exp360_cm_info_dynamic(cm_info $cm) $cm->set_no_view_link(); $cm->set_content($script); } + +/** + * Event observer for mod_exp360. + */ +function mod_exp360_event_observer($event) +{ + global $PAGE, $DB; + + // Get the course ID from the event. + $courseid = $event->courseid; + + // Check if the course contains any instances of the exp360 activity. + $sql = "SELECT COUNT(*) + FROM {course_modules} cm + JOIN {modules} m ON cm.module = m.id + JOIN {exp360} e ON cm.instance = e.id + WHERE cm.course = :courseid + AND m.name = 'exp360'"; + $params = ['courseid' => $courseid]; + $count = $DB->count_records_sql($sql, $params); + + // If the course contains at least one instance of exp360, inject the JavaScript. + if ($count > 0) { + $PAGE->requires->js('/mod/exp360/global.js'); + } +} + +/** + * Returns the list of event observers. + * + * @return array + */ +function mod_exp360_get_event_observers() +{ + return [ + [ + 'eventname' => '\core\event\course_viewed', + 'callback' => 'mod_exp360_event_observer', + ], + ]; +}