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.
This commit is contained in:
Kumi 2024-07-05 12:36:55 +02:00
parent 07632fa961
commit b58487ebb8
Signed by: kumi
GPG key ID: ECBCC9082395383F

19
lib.php
View file

@ -64,26 +64,9 @@ 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) {
global $PAGE;
$PAGE->requires->js('/mod/exp360/global.js');
}
}
/**
* Returns the list of event observers.