From 131f84f5ef95b1e7a88f8ce30c3ddb01dc10cae3 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 5 Jul 2024 12:18:34 +0200 Subject: [PATCH] feat: add renderer for dynamic modal and activity scripts Introduced a new renderer class to manage the rendering of activity scripts and modals in the exp360 module. Renderer ensures modals are loaded only once, enhancing performance. Modified lib.php to utilize the new renderer for appending necessary scripts and modal content to the course module info. --- classes/output/renderer.php | 45 +++++++++++++++++++++++++++++++++++++ lib.php | 8 ++++--- 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 classes/output/renderer.php diff --git a/classes/output/renderer.php b/classes/output/renderer.php new file mode 100644 index 0000000..77f43aa --- /dev/null +++ b/classes/output/renderer.php @@ -0,0 +1,45 @@ +"; + return $script; + } + + public function render_modals() { + if (self::$modals_rendered) { + return ''; + } + + self::$modals_rendered = true; + + $modalHTML = ' + + + '; + return $modalHTML; + } +} \ No newline at end of file diff --git a/lib.php b/lib.php index da71247..5ac58af 100644 --- a/lib.php +++ b/lib.php @@ -45,16 +45,18 @@ function exp360_delete_instance($id) function mod_exp360_cm_info_dynamic(cm_info $cm) { - global $PAGE, $DB; + global $PAGE; if ($cm->modname !== 'exp360') { return; } - $script = ""; + $renderer = $PAGE->get_renderer('mod_exp360'); + $modals = $renderer->render_modals(); + $script = $renderer->render_activity($cm->id); $cm->set_no_view_link(); - $cm->set_content($script); + $cm->set_content($script . $modals); } /**