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:
parent
07632fa961
commit
b58487ebb8
1 changed files with 2 additions and 19 deletions
21
lib.php
21
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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue