From a2ee4573a00cd170b1cc0296763ebe424b5c3986 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Tue, 1 Apr 2025 16:10:12 +0100 Subject: [PATCH 01/12] TD-5136: A custom plugin has been created to add scorm resource programatically under a specific course --- local/custom_service_api/db/services.php | 35 ++++ local/custom_service_api/externallib.php | 172 ++++++++++++++++++ .../lang/en/local_custom_service_api.php | 2 + local/custom_service_api/version.php | 29 +++ 4 files changed, 238 insertions(+) create mode 100644 local/custom_service_api/db/services.php create mode 100644 local/custom_service_api/externallib.php create mode 100644 local/custom_service_api/lang/en/local_custom_service_api.php create mode 100644 local/custom_service_api/version.php diff --git a/local/custom_service_api/db/services.php b/local/custom_service_api/db/services.php new file mode 100644 index 00000000000..e3caec0debb --- /dev/null +++ b/local/custom_service_api/db/services.php @@ -0,0 +1,35 @@ + array( + 'classname' => 'insert_scorm_resource', + 'methodname' => 'insert_scorm_resource', + 'classpath' => 'local/custom_service_api/externallib.php', + 'description' => 'Create a scorm resource under a course', + 'type' => 'write', + 'ajax' => true, + ), + +); + +$services = array( + 'Insert Scorm resource' => array( + 'functions' => array( + + 'mod_scorm_insert_scorm_resource' + ), + 'restrictedusers' => 0, + 'enabled' => 1, + // This field os optional, but requried if the `restrictedusers` value is + // set, so as to allow configuration via the Web UI. + 'shortname' => 'InsertScorm', + + // Whether to allow file downloads. + 'downloadfiles' => 0, + + // Whether to allow file uploads. + 'uploadfiles' => 0, + ) +); \ No newline at end of file diff --git a/local/custom_service_api/externallib.php b/local/custom_service_api/externallib.php new file mode 100644 index 00000000000..168e4df9df1 --- /dev/null +++ b/local/custom_service_api/externallib.php @@ -0,0 +1,172 @@ +libdir.'/externallib.php'); +require_once($CFG->dirroot.'/user/lib.php'); +require_once($CFG->dirroot.'/course/lib.php'); +require_once($CFG->dirroot.'/mod/scorm/lib.php'); +require_once($CFG->dirroot.'/mod/scorm/locallib.php'); +require_once(__DIR__.'/../../config.php'); +require_once($CFG->libdir . '/filestorage/file_storage.php'); +require_once("$CFG->dirroot/mod/scorm/datamodels/scormlib.php"); +class insert_scorm_resource extends external_api { + + + + public static function insert_scorm_resource_parameters() { + return new external_function_parameters( + array( + 'courseid' => new external_value(PARAM_TEXT, 'Course Id'), + 'section' => new external_value(PARAM_TEXT, 'section'), + 'scormname' => new external_value(PARAM_TEXT, 'scorm name'), + 'file' => new external_value(PARAM_TEXT, 'file'), + 'path' => new external_value(PARAM_TEXT, 'path') + + ) + ); + } + public static function insert_scorm_resource($courseids,$section,$scormname,$file,$path) { + global $DB,$CFG; + require_once($CFG->libdir . '/filelib.php'); + require_once($CFG->dirroot . '/course/lib.php'); + require_once($CFG->libdir . '/formslib.php'); + + require_login(); + $courseid = $courseids; // Course ID where the SCORM package will be uploaded + $scormname = $scormname;// // Name for the SCORM module + $scormfile =$path . '' . $file. '.zip'; // Path to the SCORM .zip file + + $zip = new ZipArchive; + + if ($zip->open($scormfile) === TRUE) { + // Check if imsmanifest.xml exists in the ZIP archive + if ($zip->locateName('imsmanifest.xml', ZipArchive::FL_NODIR) !== false) { + $zip->close(); + } else { + $zip->close(); + echo'imsmanifest.xml is missing from SCORM package.'; + return; + } + } else { + echo 'Failed to open SCORM package.'; + return; + } + + // Get course and context + try{ + $course = get_course($courseid); + } + catch(exception $ex) + { + echo 'Course not found'; + return; + } + + $context = context_course::instance($courseid); + + // Check permissions + require_capability('mod/scorm:addinstance', $context); + + // Create SCORM instance (if needed) + $scorm = new stdClass(); + $scorm->course = $courseid; + $scorm->name = $scormname; + $scorm->reference='Test Ref.zip'; + $scorm->intro = 'Intro to SCORM'; + $scorm->introformat = FORMAT_HTML; + $scorm->timemodified = time(); + + // Insert the SCORM instance into the database and get the instance ID + $scorm->id = $DB->insert_record('scorm', $scorm); + + // Create a new course module record + $cm = new stdClass(); + $cm->course = $courseid; + $cm->module = $DB->get_field('modules', 'id', array('name' => 'scorm')); + $cm->instance = $scorm->id; + $cm->visible = 1; + $cm->section = $section; // You can set the section if needed + + // Insert the course module + $cm->id = add_course_module($cm); //$DB->insert_record('course_modules', $cm); + + $sectionid=course_add_cm_to_section($courseid,$cm->id,$cm->section); + + // Update the record + $data = new stdClass(); + $data->id = $cm->id; // The ID of the course module to update + $data->section = $sectionid; // The new section value + + // // Update the record in the course_modules table + $DB->update_record('course_modules', $data); + // Upload the SCORM package to Moodle file storage + $fs = get_file_storage(); + $context = context_module::instance($cm->id); + + // Add the SCORM .zip package to the file area + $fileinfo = array( + 'contextid' => $context->id, + 'component' => 'mod_scorm', + 'filearea' => 'package', + 'itemid' => 0, // Item ID (could be used to reference a specific instance of the package) + 'filepath' => '/', + 'filename' => $file. '.zip' + ); + + $file = $fs->create_file_from_pathname($fileinfo, $scormfile); + + $packer = get_file_packer('application/zip'); + ; + if ($file) { + $extracted_files = $file->extract_to_storage($packer,$context->id, 'mod_scorm', 'content', 0, '/'); + echo "Extraction complete!"; + } else { + echo "ZIP file not found."; + } + + //new code for reading imsmanifest.xml + $fs = get_file_storage(); + + // Locate the extracted directory in Moodle file storage (adjust as needed) + $contextid = $context->id; // The course/module context ID + $component = 'mod_scorm'; // Change this to match your module (e.g., mod_scorm, mod_lti, etc.) + $filearea = 'content'; // File area for SCORM or Common Cartridge + $itemid = 0; // Usually 0 unless specified + $filename = 'imsmanifest.xml'; + + // Get the manifest file + $file = $fs->get_file($contextid, $component, $filearea, $itemid, '/', $filename); + $manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml'); + + + scorm_parse_scorm($scorm, $manifest); + + + + $count = 0; + $lti_updated = [ + 'message'=>'Scorm package added to course', + ]; + + + + + return $lti_updated; + } + public static function insert_scorm_resource_returns() { + return new external_single_structure( + array( + + 'message'=> new external_value(PARAM_TEXT, 'success message'), + + ) + ); + } + + + + + + + +} \ No newline at end of file diff --git a/local/custom_service_api/lang/en/local_custom_service_api.php b/local/custom_service_api/lang/en/local_custom_service_api.php new file mode 100644 index 00000000000..c5166e90235 --- /dev/null +++ b/local/custom_service_api/lang/en/local_custom_service_api.php @@ -0,0 +1,2 @@ +. + +/** + * Version details + * + * @package block_calendar_upcoming + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->version = 2024100989; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2024100290; // Requires this Moodle version. +$plugin->component = 'local_custom_service_api'; // Full name of the plugin (used for diagnostics) \ No newline at end of file From b86442f4bd9fff55f694d6f096d8b9f93c285c45 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Wed, 2 Apr 2025 15:31:19 +0100 Subject: [PATCH 02/12] TD-5136: Unit test issue resolved --- local/{custom_service_api => custom_service}/db/services.php | 2 +- local/{custom_service_api => custom_service}/externallib.php | 0 .../lang/en/local_custom_service_api.php | 0 local/{custom_service_api => custom_service}/version.php | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename local/{custom_service_api => custom_service}/db/services.php (93%) rename local/{custom_service_api => custom_service}/externallib.php (100%) rename local/{custom_service_api => custom_service}/lang/en/local_custom_service_api.php (100%) rename local/{custom_service_api => custom_service}/version.php (100%) diff --git a/local/custom_service_api/db/services.php b/local/custom_service/db/services.php similarity index 93% rename from local/custom_service_api/db/services.php rename to local/custom_service/db/services.php index e3caec0debb..df5ad8d317c 100644 --- a/local/custom_service_api/db/services.php +++ b/local/custom_service/db/services.php @@ -6,7 +6,7 @@ 'mod_scorm_insert_scorm_resource' => array( 'classname' => 'insert_scorm_resource', 'methodname' => 'insert_scorm_resource', - 'classpath' => 'local/custom_service_api/externallib.php', + 'classpath' => 'local/custom_service/externallib.php', 'description' => 'Create a scorm resource under a course', 'type' => 'write', 'ajax' => true, diff --git a/local/custom_service_api/externallib.php b/local/custom_service/externallib.php similarity index 100% rename from local/custom_service_api/externallib.php rename to local/custom_service/externallib.php diff --git a/local/custom_service_api/lang/en/local_custom_service_api.php b/local/custom_service/lang/en/local_custom_service_api.php similarity index 100% rename from local/custom_service_api/lang/en/local_custom_service_api.php rename to local/custom_service/lang/en/local_custom_service_api.php diff --git a/local/custom_service_api/version.php b/local/custom_service/version.php similarity index 100% rename from local/custom_service_api/version.php rename to local/custom_service/version.php From 9e1e393fbab0b3591eba0b081ace158388395911 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Wed, 2 Apr 2025 15:34:38 +0100 Subject: [PATCH 03/12] TD-5136: Unit test issue resolved --- .../en/{local_custom_service_api.php => local_custom_service.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename local/custom_service/lang/en/{local_custom_service_api.php => local_custom_service.php} (100%) diff --git a/local/custom_service/lang/en/local_custom_service_api.php b/local/custom_service/lang/en/local_custom_service.php similarity index 100% rename from local/custom_service/lang/en/local_custom_service_api.php rename to local/custom_service/lang/en/local_custom_service.php From 1fa59f2174af1e6d81622f3ea21e594bc9ea6a8b Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Wed, 2 Apr 2025 15:40:54 +0100 Subject: [PATCH 04/12] TD-5136: Unit test issue fix --- local/custom_service/version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local/custom_service/version.php b/local/custom_service/version.php index 872611e7472..9d93eb34b7a 100644 --- a/local/custom_service/version.php +++ b/local/custom_service/version.php @@ -26,4 +26,4 @@ $plugin->version = 2024100989; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2024100290; // Requires this Moodle version. -$plugin->component = 'local_custom_service_api'; // Full name of the plugin (used for diagnostics) \ No newline at end of file +$plugin->component = 'local_custom_service'; // Full name of the plugin (used for diagnostics) \ No newline at end of file From c8cc8f8fc786d4de593440ca7b460a8270d74840 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Wed, 2 Apr 2025 19:40:00 +0100 Subject: [PATCH 05/12] TD-5136:Unit Test fix test --- local/custom_service/externallib.php | 108 --------------------------- 1 file changed, 108 deletions(-) diff --git a/local/custom_service/externallib.php b/local/custom_service/externallib.php index 168e4df9df1..77bb7c645a4 100644 --- a/local/custom_service/externallib.php +++ b/local/custom_service/externallib.php @@ -31,115 +31,7 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil require_once($CFG->dirroot . '/course/lib.php'); require_once($CFG->libdir . '/formslib.php'); - require_login(); - $courseid = $courseids; // Course ID where the SCORM package will be uploaded - $scormname = $scormname;// // Name for the SCORM module - $scormfile =$path . '' . $file. '.zip'; // Path to the SCORM .zip file - - $zip = new ZipArchive; - - if ($zip->open($scormfile) === TRUE) { - // Check if imsmanifest.xml exists in the ZIP archive - if ($zip->locateName('imsmanifest.xml', ZipArchive::FL_NODIR) !== false) { - $zip->close(); - } else { - $zip->close(); - echo'imsmanifest.xml is missing from SCORM package.'; - return; - } - } else { - echo 'Failed to open SCORM package.'; - return; - } - - // Get course and context - try{ - $course = get_course($courseid); - } - catch(exception $ex) - { - echo 'Course not found'; - return; - } - - $context = context_course::instance($courseid); - - // Check permissions - require_capability('mod/scorm:addinstance', $context); - - // Create SCORM instance (if needed) - $scorm = new stdClass(); - $scorm->course = $courseid; - $scorm->name = $scormname; - $scorm->reference='Test Ref.zip'; - $scorm->intro = 'Intro to SCORM'; - $scorm->introformat = FORMAT_HTML; - $scorm->timemodified = time(); - - // Insert the SCORM instance into the database and get the instance ID - $scorm->id = $DB->insert_record('scorm', $scorm); - - // Create a new course module record - $cm = new stdClass(); - $cm->course = $courseid; - $cm->module = $DB->get_field('modules', 'id', array('name' => 'scorm')); - $cm->instance = $scorm->id; - $cm->visible = 1; - $cm->section = $section; // You can set the section if needed - - // Insert the course module - $cm->id = add_course_module($cm); //$DB->insert_record('course_modules', $cm); - - $sectionid=course_add_cm_to_section($courseid,$cm->id,$cm->section); - - // Update the record - $data = new stdClass(); - $data->id = $cm->id; // The ID of the course module to update - $data->section = $sectionid; // The new section value - - // // Update the record in the course_modules table - $DB->update_record('course_modules', $data); - // Upload the SCORM package to Moodle file storage - $fs = get_file_storage(); - $context = context_module::instance($cm->id); - - // Add the SCORM .zip package to the file area - $fileinfo = array( - 'contextid' => $context->id, - 'component' => 'mod_scorm', - 'filearea' => 'package', - 'itemid' => 0, // Item ID (could be used to reference a specific instance of the package) - 'filepath' => '/', - 'filename' => $file. '.zip' - ); - - $file = $fs->create_file_from_pathname($fileinfo, $scormfile); - - $packer = get_file_packer('application/zip'); - ; - if ($file) { - $extracted_files = $file->extract_to_storage($packer,$context->id, 'mod_scorm', 'content', 0, '/'); - echo "Extraction complete!"; - } else { - echo "ZIP file not found."; - } - - //new code for reading imsmanifest.xml - $fs = get_file_storage(); - - // Locate the extracted directory in Moodle file storage (adjust as needed) - $contextid = $context->id; // The course/module context ID - $component = 'mod_scorm'; // Change this to match your module (e.g., mod_scorm, mod_lti, etc.) - $filearea = 'content'; // File area for SCORM or Common Cartridge - $itemid = 0; // Usually 0 unless specified - $filename = 'imsmanifest.xml'; - - // Get the manifest file - $file = $fs->get_file($contextid, $component, $filearea, $itemid, '/', $filename); - $manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml'); - - scorm_parse_scorm($scorm, $manifest); From 157a241c01025f732aa9549df98c520717117379 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Fri, 4 Apr 2025 08:57:44 +0100 Subject: [PATCH 06/12] TD-5136:Unit test issue fix --- .../classes/privacy/provider.php | 20 ++++ local/custom_service/externallib.php | 109 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 local/custom_service/classes/privacy/provider.php diff --git a/local/custom_service/classes/privacy/provider.php b/local/custom_service/classes/privacy/provider.php new file mode 100644 index 00000000000..fef3a05e9c0 --- /dev/null +++ b/local/custom_service/classes/privacy/provider.php @@ -0,0 +1,20 @@ +libdir . '/filelib.php'); require_once($CFG->dirroot . '/course/lib.php'); require_once($CFG->libdir . '/formslib.php'); + + require_login(); + $courseid = $courseids; // Course ID where the SCORM package will be uploaded + $scormname = $scormname;// // Name for the SCORM module + $scormfile =$path . '' . $file. '.zip'; // Path to the SCORM .zip file + + $zip = new ZipArchive; + + if ($zip->open($scormfile) === TRUE) { + // Check if imsmanifest.xml exists in the ZIP archive + if ($zip->locateName('imsmanifest.xml', ZipArchive::FL_NODIR) !== false) { + $zip->close(); + } else { + $zip->close(); + echo'imsmanifest.xml is missing from SCORM package.'; + return; + } + } else { + echo 'Failed to open SCORM package.'; + return; + } + + // Get course and context + try{ + $course = get_course($courseid); + } + catch(exception $ex) + { + echo 'Course not found'; + return; + } + + $context = context_course::instance($courseid); + + // Check permissions + require_capability('mod/scorm:addinstance', $context); + + // Create SCORM instance (if needed) + $scorm = new stdClass(); + $scorm->course = $courseid; + $scorm->name = $scormname; + $scorm->reference='Test Ref.zip'; + $scorm->intro = 'Intro to SCORM'; + $scorm->introformat = FORMAT_HTML; + $scorm->timemodified = time(); + + // Insert the SCORM instance into the database and get the instance ID + $scorm->id = $DB->insert_record('scorm', $scorm); + + // Create a new course module record + $cm = new stdClass(); + $cm->course = $courseid; + $cm->module = $DB->get_field('modules', 'id', array('name' => 'scorm')); + $cm->instance = $scorm->id; + $cm->visible = 1; + $cm->section = $section; // You can set the section if needed + + // Insert the course module + $cm->id = add_course_module($cm); //$DB->insert_record('course_modules', $cm); + + $sectionid=course_add_cm_to_section($courseid,$cm->id,$cm->section); + + // Update the record + $data = new stdClass(); + $data->id = $cm->id; // The ID of the course module to update + $data->section = $sectionid; // The new section value + + // // Update the record in the course_modules table + $DB->update_record('course_modules', $data); + // Upload the SCORM package to Moodle file storage + $fs = get_file_storage(); + $context = context_module::instance($cm->id); + + // Add the SCORM .zip package to the file area + $fileinfo = array( + 'contextid' => $context->id, + 'component' => 'mod_scorm', + 'filearea' => 'package', + 'itemid' => 0, // Item ID (could be used to reference a specific instance of the package) + 'filepath' => '/', + 'filename' => $file. '.zip' + ); + + $file = $fs->create_file_from_pathname($fileinfo, $scormfile); + + $packer = get_file_packer('application/zip'); + ; + if ($file) { + $extracted_files = $file->extract_to_storage($packer,$context->id, 'mod_scorm', 'content', 0, '/'); + echo "Extraction complete!"; + } else { + echo "ZIP file not found."; + } + + //new code for reading imsmanifest.xml + $fs = get_file_storage(); + + // Locate the extracted directory in Moodle file storage (adjust as needed) + $contextid = $context->id; // The course/module context ID + $component = 'mod_scorm'; // Change this to match your module (e.g., mod_scorm, mod_lti, etc.) + $filearea = 'content'; // File area for SCORM or Common Cartridge + $itemid = 0; // Usually 0 unless specified + $filename = 'imsmanifest.xml'; + + // Get the manifest file + $file = $fs->get_file($contextid, $component, $filearea, $itemid, '/', $filename); + $manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml'); + + scorm_parse_scorm($scorm, $manifest); From 98bdc22c4f130a2d992895cac074648c43759293 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Fri, 4 Apr 2025 09:19:10 +0100 Subject: [PATCH 07/12] TD-5136:Unit test fail fix --- local/custom_service/classes/privacy/provider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local/custom_service/classes/privacy/provider.php b/local/custom_service/classes/privacy/provider.php index fef3a05e9c0..30265e0d759 100644 --- a/local/custom_service/classes/privacy/provider.php +++ b/local/custom_service/classes/privacy/provider.php @@ -6,7 +6,7 @@ use core_privacy\local\metadata\provider; use core_privacy\local\metadata\collection; -class provider implements provider { +class provider implements \core_privacy\local\metadata\provider { /** * Returns metadata about this plugin’s data handling. * Since this plugin does not store any user data, it returns an empty collection. From d7c89bbe4fece910a20b5f65942f7f80a1a42077 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Fri, 4 Apr 2025 09:58:54 +0100 Subject: [PATCH 08/12] TD-5136:Unit test issue fix --- local/custom_service/classes/privacy/provider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/local/custom_service/classes/privacy/provider.php b/local/custom_service/classes/privacy/provider.php index 30265e0d759..754afe2852a 100644 --- a/local/custom_service/classes/privacy/provider.php +++ b/local/custom_service/classes/privacy/provider.php @@ -3,7 +3,6 @@ defined('MOODLE_INTERNAL') || die; -use core_privacy\local\metadata\provider; use core_privacy\local\metadata\collection; class provider implements \core_privacy\local\metadata\provider { From 8c9c45bc7d708f92bed480932b320afda7008a80 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Fri, 4 Apr 2025 12:12:11 +0100 Subject: [PATCH 09/12] TD-5136: Unit test issue fix --- .../classes/privacy/provider.php | 2 +- .../{custom_service => local_custom_service}/db/services.php | 2 +- .../{custom_service => local_custom_service}/externallib.php | 0 .../lang/en/local_custom_service.php | 0 local/{custom_service => local_custom_service}/version.php | 5 ++++- 5 files changed, 6 insertions(+), 3 deletions(-) rename local/{custom_service => local_custom_service}/classes/privacy/provider.php (93%) rename local/{custom_service => local_custom_service}/db/services.php (92%) rename local/{custom_service => local_custom_service}/externallib.php (100%) rename local/{custom_service => local_custom_service}/lang/en/local_custom_service.php (100%) rename local/{custom_service => local_custom_service}/version.php (91%) diff --git a/local/custom_service/classes/privacy/provider.php b/local/local_custom_service/classes/privacy/provider.php similarity index 93% rename from local/custom_service/classes/privacy/provider.php rename to local/local_custom_service/classes/privacy/provider.php index 754afe2852a..3ed72629506 100644 --- a/local/custom_service/classes/privacy/provider.php +++ b/local/local_custom_service/classes/privacy/provider.php @@ -1,5 +1,5 @@ array( 'classname' => 'insert_scorm_resource', 'methodname' => 'insert_scorm_resource', - 'classpath' => 'local/custom_service/externallib.php', + 'classpath' => 'local/local_custom_service/externallib.php', 'description' => 'Create a scorm resource under a course', 'type' => 'write', 'ajax' => true, diff --git a/local/custom_service/externallib.php b/local/local_custom_service/externallib.php similarity index 100% rename from local/custom_service/externallib.php rename to local/local_custom_service/externallib.php diff --git a/local/custom_service/lang/en/local_custom_service.php b/local/local_custom_service/lang/en/local_custom_service.php similarity index 100% rename from local/custom_service/lang/en/local_custom_service.php rename to local/local_custom_service/lang/en/local_custom_service.php diff --git a/local/custom_service/version.php b/local/local_custom_service/version.php similarity index 91% rename from local/custom_service/version.php rename to local/local_custom_service/version.php index 9d93eb34b7a..1b97836939c 100644 --- a/local/custom_service/version.php +++ b/local/local_custom_service/version.php @@ -26,4 +26,7 @@ $plugin->version = 2024100989; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2024100290; // Requires this Moodle version. -$plugin->component = 'local_custom_service'; // Full name of the plugin (used for diagnostics) \ No newline at end of file +$plugin->component = 'local_custom_service'; // Full name of the plugin (used for diagnostics) +$plugin->privacy = [ + 'provider' => 'local_custom_service\privacy\provider' +]; \ No newline at end of file From 75e86912dfa12e56c97831bc5f12d30c706911a9 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Fri, 4 Apr 2025 12:16:33 +0100 Subject: [PATCH 10/12] TD-5136:Unit test fix --- .../classes/privacy/provider.php | 0 local/{local_custom_service => custom_service}/db/services.php | 2 +- local/{local_custom_service => custom_service}/externallib.php | 0 .../lang/en/local_custom_service.php | 0 local/{local_custom_service => custom_service}/version.php | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename local/{local_custom_service => custom_service}/classes/privacy/provider.php (100%) rename local/{local_custom_service => custom_service}/db/services.php (92%) rename local/{local_custom_service => custom_service}/externallib.php (100%) rename local/{local_custom_service => custom_service}/lang/en/local_custom_service.php (100%) rename local/{local_custom_service => custom_service}/version.php (100%) diff --git a/local/local_custom_service/classes/privacy/provider.php b/local/custom_service/classes/privacy/provider.php similarity index 100% rename from local/local_custom_service/classes/privacy/provider.php rename to local/custom_service/classes/privacy/provider.php diff --git a/local/local_custom_service/db/services.php b/local/custom_service/db/services.php similarity index 92% rename from local/local_custom_service/db/services.php rename to local/custom_service/db/services.php index 5dc039dc0b6..df5ad8d317c 100644 --- a/local/local_custom_service/db/services.php +++ b/local/custom_service/db/services.php @@ -6,7 +6,7 @@ 'mod_scorm_insert_scorm_resource' => array( 'classname' => 'insert_scorm_resource', 'methodname' => 'insert_scorm_resource', - 'classpath' => 'local/local_custom_service/externallib.php', + 'classpath' => 'local/custom_service/externallib.php', 'description' => 'Create a scorm resource under a course', 'type' => 'write', 'ajax' => true, diff --git a/local/local_custom_service/externallib.php b/local/custom_service/externallib.php similarity index 100% rename from local/local_custom_service/externallib.php rename to local/custom_service/externallib.php diff --git a/local/local_custom_service/lang/en/local_custom_service.php b/local/custom_service/lang/en/local_custom_service.php similarity index 100% rename from local/local_custom_service/lang/en/local_custom_service.php rename to local/custom_service/lang/en/local_custom_service.php diff --git a/local/local_custom_service/version.php b/local/custom_service/version.php similarity index 100% rename from local/local_custom_service/version.php rename to local/custom_service/version.php From d9b6caab730735e9273ae59f4c8cbd8951eba52a Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Fri, 4 Apr 2025 15:44:22 +0100 Subject: [PATCH 11/12] TD-5136:Unit test fix --- .../custom_service/classes/privacy/provider.php | 17 +++++------------ .../lang/en/local_custom_service.php | 3 ++- local/custom_service/version.php | 4 +--- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/local/custom_service/classes/privacy/provider.php b/local/custom_service/classes/privacy/provider.php index 3ed72629506..9c5510b6950 100644 --- a/local/custom_service/classes/privacy/provider.php +++ b/local/custom_service/classes/privacy/provider.php @@ -3,17 +3,10 @@ defined('MOODLE_INTERNAL') || die; -use core_privacy\local\metadata\collection; - -class provider implements \core_privacy\local\metadata\provider { - /** - * Returns metadata about this plugin’s data handling. - * Since this plugin does not store any user data, it returns an empty collection. - * - * @param collection $collection The metadata collection. - * @return collection The updated metadata collection. - */ - public static function get_metadata(collection $collection) : collection { - return $collection; +use core_privacy\local\request\null_provider; + +class provider implements null_provider { + public static function get_reason() : string { + return 'privacy:metadata'; } } \ No newline at end of file diff --git a/local/custom_service/lang/en/local_custom_service.php b/local/custom_service/lang/en/local_custom_service.php index c5166e90235..6fdc0b44600 100644 --- a/local/custom_service/lang/en/local_custom_service.php +++ b/local/custom_service/lang/en/local_custom_service.php @@ -1,2 +1,3 @@ version = 2024100989; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2024100290; // Requires this Moodle version. $plugin->component = 'local_custom_service'; // Full name of the plugin (used for diagnostics) -$plugin->privacy = [ - 'provider' => 'local_custom_service\privacy\provider' -]; \ No newline at end of file +$plugin->privacy = ['provider' => 'local_custom_service\classes\privacy\provider']; \ No newline at end of file From 48e1dbc9393204080e592e6446dbc9ad3f887214 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Fri, 4 Apr 2025 21:09:31 +0100 Subject: [PATCH 12/12] TD-5136:Unit test fix --- .../classes/privacy/provider.php | 3 +- local/custom_service/externallib.php | 41 +++++++++---------- local/custom_service/tests/phpunit.xml | 9 ++++ local/custom_service/tests/privacy_test.php | 17 ++++++++ local/custom_service/version.php | 4 +- 5 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 local/custom_service/tests/phpunit.xml create mode 100644 local/custom_service/tests/privacy_test.php diff --git a/local/custom_service/classes/privacy/provider.php b/local/custom_service/classes/privacy/provider.php index 9c5510b6950..6e0fc064f09 100644 --- a/local/custom_service/classes/privacy/provider.php +++ b/local/custom_service/classes/privacy/provider.php @@ -3,9 +3,8 @@ defined('MOODLE_INTERNAL') || die; -use core_privacy\local\request\null_provider; -class provider implements null_provider { +class provider implements \core_privacy\local\metadata\null_provider { public static function get_reason() : string { return 'privacy:metadata'; } diff --git a/local/custom_service/externallib.php b/local/custom_service/externallib.php index 9bede707c6b..0019202ed9e 100644 --- a/local/custom_service/externallib.php +++ b/local/custom_service/externallib.php @@ -30,12 +30,12 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil require_once($CFG->libdir . '/filelib.php'); require_once($CFG->dirroot . '/course/lib.php'); require_once($CFG->libdir . '/formslib.php'); - - require_login(); + + require_login(); $courseid = $courseids; // Course ID where the SCORM package will be uploaded $scormname = $scormname;// // Name for the SCORM module $scormfile =$path . '' . $file. '.zip'; // Path to the SCORM .zip file - + $zip = new ZipArchive; if ($zip->open($scormfile) === TRUE) { @@ -51,7 +51,7 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil echo 'Failed to open SCORM package.'; return; } - + // Get course and context try{ $course = get_course($courseid); @@ -63,10 +63,10 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil } $context = context_course::instance($courseid); - + // Check permissions require_capability('mod/scorm:addinstance', $context); - + // Create SCORM instance (if needed) $scorm = new stdClass(); $scorm->course = $courseid; @@ -75,10 +75,10 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil $scorm->intro = 'Intro to SCORM'; $scorm->introformat = FORMAT_HTML; $scorm->timemodified = time(); - + // Insert the SCORM instance into the database and get the instance ID $scorm->id = $DB->insert_record('scorm', $scorm); - + // Create a new course module record $cm = new stdClass(); $cm->course = $courseid; @@ -86,23 +86,23 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil $cm->instance = $scorm->id; $cm->visible = 1; $cm->section = $section; // You can set the section if needed - + // Insert the course module $cm->id = add_course_module($cm); //$DB->insert_record('course_modules', $cm); - + $sectionid=course_add_cm_to_section($courseid,$cm->id,$cm->section); - + // Update the record $data = new stdClass(); $data->id = $cm->id; // The ID of the course module to update $data->section = $sectionid; // The new section value - + // // Update the record in the course_modules table $DB->update_record('course_modules', $data); // Upload the SCORM package to Moodle file storage $fs = get_file_storage(); $context = context_module::instance($cm->id); - + // Add the SCORM .zip package to the file area $fileinfo = array( 'contextid' => $context->id, @@ -112,7 +112,7 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil 'filepath' => '/', 'filename' => $file. '.zip' ); - + $file = $fs->create_file_from_pathname($fileinfo, $scormfile); $packer = get_file_packer('application/zip'); @@ -126,14 +126,14 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil //new code for reading imsmanifest.xml $fs = get_file_storage(); - + // Locate the extracted directory in Moodle file storage (adjust as needed) $contextid = $context->id; // The course/module context ID $component = 'mod_scorm'; // Change this to match your module (e.g., mod_scorm, mod_lti, etc.) $filearea = 'content'; // File area for SCORM or Common Cartridge $itemid = 0; // Usually 0 unless specified $filename = 'imsmanifest.xml'; - + // Get the manifest file $file = $fs->get_file($contextid, $component, $filearea, $itemid, '/', $filename); $manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml'); @@ -141,15 +141,14 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil scorm_parse_scorm($scorm, $manifest); - - + $count = 0; $lti_updated = [ 'message'=>'Scorm package added to course', ]; - + return $lti_updated; @@ -157,9 +156,9 @@ public static function insert_scorm_resource($courseids,$section,$scormname,$fil public static function insert_scorm_resource_returns() { return new external_single_structure( array( - + 'ids' => new external_value(PARAM_TEXT, 'course ids'), 'message'=> new external_value(PARAM_TEXT, 'success message'), - + 'updated'=>new external_value(PARAM_TEXT,'Items Updated') ) ); } diff --git a/local/custom_service/tests/phpunit.xml b/local/custom_service/tests/phpunit.xml new file mode 100644 index 00000000000..3e7ea1679a7 --- /dev/null +++ b/local/custom_service/tests/phpunit.xml @@ -0,0 +1,9 @@ + + + + privacy_test.php + + diff --git a/local/custom_service/tests/privacy_test.php b/local/custom_service/tests/privacy_test.php new file mode 100644 index 00000000000..8a3736ce352 --- /dev/null +++ b/local/custom_service/tests/privacy_test.php @@ -0,0 +1,17 @@ +dirroot . '/local/custom_service/classes/privacy/provider.php'); + +use core_privacy\tests\provider_testcase; +use local_custom_service\privacy\provider; + +class local_custom_service_privacy_test extends provider_testcase { + + public function test_privacy_provider() { + $this->assertInstanceOf( + \core_privacy\local\metadata\null_provider::class, + new provider() + ); + } +} diff --git a/local/custom_service/version.php b/local/custom_service/version.php index 9d2e51fe9e3..11103b82a41 100644 --- a/local/custom_service/version.php +++ b/local/custom_service/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024100989; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2024100990; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2024100290; // Requires this Moodle version. $plugin->component = 'local_custom_service'; // Full name of the plugin (used for diagnostics) -$plugin->privacy = ['provider' => 'local_custom_service\classes\privacy\provider']; \ No newline at end of file +$plugin->privacy = ['provider' => 'local_custom_service\privacy\provider']; \ No newline at end of file