From b58487ebb81ba5e5b0de2e695d57b994840c5421 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 5 Jul 2024 12:36:55 +0200 Subject: [PATCH] fix: always load JS for exp360 events Simplified the event observer function to always inject the exp360 global JavaScript on relevant pages, removing the conditional check for exp360 instances within the course. This ensures consistent loading behavior and reduces database queries. --- lib.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/lib.php b/lib.php index 9884454..8237aff 100644 --- a/lib.php +++ b/lib.php @@ -64,25 +64,8 @@ function mod_exp360_cm_info_dynamic(cm_info $cm) */ 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'); - } + global $PAGE; + $PAGE->requires->js('/mod/exp360/global.js'); } /**