Kumi
18cbc156dc
Refactored to use reflection for accessing private URL properties to bypass a bug affecting the path property within moodle_url objects. This addresses an issue where the dynamic content rendering function prematurely exits when navigating to `modedit.php`. Improved function formatting for `mod_exp360_supports` for readability.
91 lines
2.1 KiB
PHP
91 lines
2.1 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;
|
|
}
|
|
|
|
// Create a reflection of $PATH so we can access protected properties
|
|
$reflection = new ReflectionClass($PAGE);
|
|
$urlProperty = $reflection->getProperty('_url');
|
|
$urlProperty->setAccessible(true);
|
|
|
|
// Get the value of _url property, which is a moodle_url object
|
|
$urlObject = $urlProperty->getValue($PAGE);
|
|
|
|
// Now access the path property within the moodle_url object
|
|
$urlReflection = new ReflectionClass($urlObject);
|
|
$pathProperty = $urlReflection->getProperty('path');
|
|
$pathProperty->setAccessible(true);
|
|
|
|
// Get the value of the path property
|
|
$pathValue = $pathProperty->getValue($urlObject);
|
|
|
|
// All of this only to bypass a little bug
|
|
if ($pathValue == '/course/modedit.php') {
|
|
return;
|
|
}
|
|
|
|
$renderer = $PAGE->get_renderer('mod_exp360');
|
|
$modals = $renderer->render_modals();
|
|
$script = $renderer->render_activity($cm->id, $cm->get_formatted_name());
|
|
|
|
$cm->set_no_view_link();
|
|
$cm->set_content($modals . $script);
|
|
}
|
|
|
|
function mod_exp360_supports($feature)
|
|
{
|
|
switch ($feature) {
|
|
case FEATURE_COMPLETION_TRACKS_VIEWS:
|
|
return true;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|