troodle-expcontent/lib.php
Kumi b58487ebb8
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.
2024-07-05 12:36:55 +02:00

84 lines
1.6 KiB
PHP

<?php
defined('MOODLE_INTERNAL') || die();
function exp360_add_instance($exp360)
{
global $DB;
$exp360->timemodified = time();
$exp360->timecreated = time();
// Process standard intro fields.
$exp360->introformat = FORMAT_HTML;
$exp360->intro = '';
return $DB->insert_record('exp360', $exp360);
}
function exp360_update_instance($exp360)
{
global $DB;
$exp360->timemodified = time();
$exp360->id = $exp360->instance;
// Process standard intro fields.
$exp360->introformat = FORMAT_HTML;
$exp360->intro = '';
return $DB->update_record('exp360', $exp360);
}
function exp360_delete_instance($id)
{
global $DB;
if (!$exp360 = $DB->get_record('exp360', array('id' => $id))) {
return false;
}
$DB->delete_records('exp360', array('id' => $exp360->id));
return true;
}
function mod_exp360_cm_info_dynamic(cm_info $cm)
{
global $PAGE;
if ($cm->modname !== 'exp360') {
return;
}
$renderer = $PAGE->get_renderer('mod_exp360');
$modals = $renderer->render_modals();
$script = $renderer->render_activity($cm->id);
$cm->set_no_view_link();
$cm->set_content($modals . $script);
}
/**
* Event observer for mod_exp360.
*/
function mod_exp360_event_observer($event)
{
global $PAGE;
$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',
],
];
}