From 5b45d9ea822814d33c6ee8de51954db18720443d Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 5 Jul 2024 11:13:58 +0200 Subject: [PATCH] =?UTF-8?q?feat(exp360):=20add=20EXP360=20module=20for=20e?= =?UTF-8?q?mbedding=20360=C2=B0=20content?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce the EXP360 activity module to embed interactive 360° content in Moodle. This update includes: - Database schema for the exp360 table. - Language support for the module. - Frontend form to create exp360 activities. - Script to handle 360° content embedding within a modal. - Two new PHP scripts to display and serve 360° content. - Version and plugin initialization. These changes allow users to seamlessly integrate and interact with 360° content within Moodle courses. --- db/install.xml | 17 +++ lang/en/exp360.php | 10 ++ mod_form.php | 26 ++++ script.js | 336 +++++++++++++++++++++------------------------ test.html | 50 +++++++ version.php | 7 + view.php | 36 +++++ view_content.php | 66 +++++++++ 8 files changed, 369 insertions(+), 179 deletions(-) create mode 100644 db/install.xml create mode 100644 lang/en/exp360.php create mode 100644 mod_form.php create mode 100644 test.html create mode 100644 version.php create mode 100644 view.php create mode 100644 view_content.php diff --git a/db/install.xml b/db/install.xml new file mode 100644 index 0000000..735727e --- /dev/null +++ b/db/install.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/lang/en/exp360.php b/lang/en/exp360.php new file mode 100644 index 0000000..078519e --- /dev/null +++ b/lang/en/exp360.php @@ -0,0 +1,10 @@ +dirroot/course/moodleform_mod.php"); + +class mod_exp360_mod_form extends moodleform_mod { + public function definition() { + $mform = $this->_form; + + $mform->addElement('header', 'general', get_string('general', 'form')); + + $mform->addElement('text', 'name', get_string('exp360name', 'exp360'), array('size' => '64')); + $mform->setType('name', PARAM_TEXT); + $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', null, 'maxlength', 255, 'client'); + + $this->standard_intro_elements(); + + $mform->addElement('text', 'content_id', get_string('contentid', 'exp360'), array('size' => '64')); + $mform->setType('content_id', PARAM_TEXT); + $mform->addRule('content_id', null, 'required', null, 'client'); + + $this->standard_coursemodule_elements(); + + $this->add_action_buttons(); + } +} \ No newline at end of file diff --git a/script.js b/script.js index d3e88ce..c872d74 100644 --- a/script.js +++ b/script.js @@ -1,214 +1,192 @@ -function loadScript(url, integrity, crossorigin) { - return new Promise((resolve, reject) => { - const script = document.createElement("script"); - script.src = url; - script.integrity = integrity; - script.crossOrigin = crossorigin; - script.onload = () => resolve(script); - script.onerror = () => reject(new Error(`Failed to load script: ${url}`)); - document.head.appendChild(script); - }); -} +(function () { + function loadScript(url, integrity, crossorigin) { + return new Promise((resolve, reject) => { + const script = document.createElement("script"); + script.src = url; + script.integrity = integrity; + script.crossOrigin = crossorigin; + script.onload = () => resolve(script); + script.onerror = () => reject(new Error(`Failed to load script: ${url}`)); + document.head.appendChild(script); + }); + } -function getFeedbackLinks() { - // Select all elements with the class "stretched-link" - const links = document.querySelectorAll("a.stretched-link"); - - // Initialize an array to store the href attributes - const feedbackLinks = []; - - // Iterate through the selected links - links.forEach((link) => { - const href = link.getAttribute("href"); - // Check if the href includes "/feedback/" - if (href) { - if (href.includes("/feedback/")) { - feedbackLinks.push(href); - } else if (href.includes("/quiz/")) { - feedbackLinks.push(href); + function getFeedbackLinks() { + const links = document.querySelectorAll("a.stretched-link"); + const feedbackLinks = []; + links.forEach((link) => { + const href = link.getAttribute("href"); + if (href) { + if (href.includes("/feedback/")) { + feedbackLinks.push(href); + } else if (href.includes("/quiz/")) { + feedbackLinks.push(href); + } } - } + }); + return feedbackLinks; + } + + var currentScript = document.currentScript; + + var myModal = document.getElementById("fullScreenModal"); + + myModal.addEventListener("shown.bs.modal", function () { + var modalContent = myModal.querySelector(".modal-content"); + var modalWidth = modalContent.offsetWidth; + var modalHeight = modalContent.offsetHeight; + + const modalIframe = window.$("#modal-iframe"); + + modalIframe.css("width", "100%"); + modalIframe.css("height", "100%"); + modalIframe.css("border", "none"); }); - return feedbackLinks; -} + loadScript( + "https://code.jquery.com/jquery-3.7.1.min.js", + "sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=", + "anonymous" + ) + .then(() => { + console.log("jQuery loaded successfully"); + window.$ = jQuery; + return loadScript( + "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js", + "sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz", + "anonymous" + ); + }) + .then(() => { + console.log("Bootstrap loaded successfully"); + var scriptId = "script-" + Math.random().toString(36).substring(2, 9); + currentScript.id = scriptId; -var currentScript = document.currentScript; + var contentUrl = "/mod/exp360/view_content.php?id=" + $(currentScript).attr("data-activity-id"); -var myModal = document.getElementById("fullScreenModal"); - -myModal.addEventListener("shown.bs.modal", function () { - var modalContent = myModal.querySelector(".modal-content"); - var modalWidth = modalContent.offsetWidth; - var modalHeight = modalContent.offsetHeight; - - const modalIframe = window.$("#modal-iframe"); - - modalIframe.css("width", "100%"); - modalIframe.css("height", "100%"); - modalIframe.css("border", "none"); -}); - -loadScript( - "https://code.jquery.com/jquery-3.7.1.min.js", - "sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=", - "anonymous" -) - .then(() => { - console.log("jQuery loaded successfully"); - window.$ = jQuery; - return loadScript( - "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js", - "sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz", - "anonymous" - ); - }) - .then(() => { - console.log("Bootstrap loaded successfully"); - var scriptId = "script-" + Math.random().toString(36).substring(2, 9); - currentScript.id = scriptId; - - contentUrl = $(currentScript).attr("data-content-url"); - - function openInModal(url, block) { - $("#modal-iframe").attr("src", url); - if (block) { - $("#fullScreenModal").attr("data-block", block); - } else { - $("#fullScreenModal").removeAttr("data-block"); + function openInModal(url, block) { + $("#modal-iframe").attr("src", url); + if (block) { + $("#fullScreenModal").attr("data-block", block); + } else { + $("#fullScreenModal").removeAttr("data-block"); + } } - } - function showContent(url, block) { - bootstrap.Modal.getOrCreateInstance( - document.getElementById("fullScreenModal") - ).show(); - if (url) { - openInModal(url, block); + function showContent(url, block) { + bootstrap.Modal.getOrCreateInstance( + document.getElementById("fullScreenModal") + ).show(); + if (url) { + openInModal(url, block); + } } - } - function hideContent() { - bootstrap.Modal.getOrCreateInstance( - document.getElementById("fullScreenModal") - ).hide(); - openInModal("about:blank"); - } + function hideContent() { + bootstrap.Modal.getOrCreateInstance( + document.getElementById("fullScreenModal") + ).hide(); + openInModal("about:blank"); + } - async function nextContent() { - // Get the currently executing + + + + diff --git a/version.php b/version.php new file mode 100644 index 0000000..5266642 --- /dev/null +++ b/version.php @@ -0,0 +1,7 @@ +version = 2024070500; // The current module version (Date: YYYYMMDDXX) +$plugin->requires = 2021051700; // Requires this Moodle version +$plugin->component = 'mod_exp360'; // Full name of the plugin (used for diagnostics) \ No newline at end of file diff --git a/view.php b/view.php new file mode 100644 index 0000000..19f65d5 --- /dev/null +++ b/view.php @@ -0,0 +1,36 @@ +get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $exp360 = $DB->get_record('exp360', array('id' => $cm->instance), '*', MUST_EXIST); +} else if ($n) { + $exp360 = $DB->get_record('exp360', array('id' => $n), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $exp360->course), '*', MUST_EXIST); + $cm = get_coursemodule_from_instance('exp360', $exp360->id, $course->id, false, MUST_EXIST); +} else { + print_error('You must specify a course_module ID or an instance ID'); +} + +require_login($course, true, $cm); + +$PAGE->set_url('/mod/exp360/view.php', array('id' => $cm->id)); +$PAGE->set_title(format_string($exp360->name)); +$PAGE->set_heading(format_string($course->fullname)); + +echo $OUTPUT->header(); + +$content_id = $exp360->content_id; + +echo ""; + +echo $OUTPUT->footer(); diff --git a/view_content.php b/view_content.php new file mode 100644 index 0000000..c34fde0 --- /dev/null +++ b/view_content.php @@ -0,0 +1,66 @@ +get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$exp360 = $DB->get_record('exp360', array('id' => $cm->instance), '*', MUST_EXIST); + +require_login($course, true, $cm); + +$content_id = $exp360->content_id; + +?> + + + + + + + + + + + + + + \ No newline at end of file