feat: Include activity name in rendered script tag

Updated the `render_activity` method to accept an additional parameter for activity name and include it in the script tag data attributes. This allows for more descriptive data handling on the client side. Adjusted calls to this method to provide the necessary activity name. Improved readability of the code by adhering to standard formatting practices.
This commit is contained in:
Kumi 2024-09-23 09:05:20 +02:00
parent 4ac9f46986
commit a40ffdf41f
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 19 additions and 16 deletions

View file

@ -6,23 +6,26 @@ defined('MOODLE_INTERNAL') || die();
use plugin_renderer_base;
class renderer extends plugin_renderer_base {
class renderer extends plugin_renderer_base
{
private static $modals_rendered = false;
private static $modals_rendered = false;
public function render_activity($activity_id) {
$script = "<script data-activity-id='$activity_id' src='/mod/exp360/script.js'></>";
return $script;
public function render_activity($activity_id, $activity_name)
{
$script = "<script data-activity-id='$activity_id' data-activity-name='$activity_name' src='/mod/exp360/script.js'></script>";
return $script;
}
public function render_modals()
{
if (self::$modals_rendered) {
return '';
}
public function render_modals() {
if (self::$modals_rendered) {
return '';
}
self::$modals_rendered = true;
self::$modals_rendered = true;
$modalHTML = '
$modalHTML = '
<div id="fullScreenModal" class="modal" tabindex="-1"
aria-labelledby="modalLabel" aria-hidden="true">
<div style="background-color:#294084;" class="modal-dialog modal-fullscreen">
@ -40,6 +43,6 @@ class renderer extends plugin_renderer_base {
</div>
</div>
';
return $modalHTML;
}
return $modalHTML;
}
}

View file

@ -53,7 +53,7 @@ function mod_exp360_cm_info_dynamic(cm_info $cm)
$renderer = $PAGE->get_renderer('mod_exp360');
$modals = $renderer->render_modals();
$script = $renderer->render_activity($cm->id);
$script = $renderer->render_activity($cm->id, $cm->name);
$cm->set_no_view_link();
$cm->set_content($modals . $script);