From 1d76dd714c56eb5ca7a303d13b2a9a087ee190bb Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Wed, 16 May 2018 10:18:55 +0200 Subject: [PATCH] MDL-62449 scorm: Move related data to data in the privacy export --- mod/scorm/classes/privacy/provider.php | 24 +++++++++++++---------- mod/scorm/lang/en/scorm.php | 2 ++ mod/scorm/tests/privacy_test.php | 27 ++++++++++++++++++++------ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/mod/scorm/classes/privacy/provider.php b/mod/scorm/classes/privacy/provider.php index 72cdb3dcdd1..3d6c1c74879 100644 --- a/mod/scorm/classes/privacy/provider.php +++ b/mod/scorm/classes/privacy/provider.php @@ -134,7 +134,6 @@ class provider implements } // Get scoes_track data. - $subcontext = []; list($insql, $inparams) = $DB->get_in_or_equal($contexts, SQL_PARAMS_NAMED); $sql = "SELECT ss.id, ss.attempt, @@ -162,14 +161,17 @@ class provider implements } $scoestracks->close(); - // The scoes_track data is organised in: {Course name}/{SCORM activity name}/attempt-X.json. + // The scoes_track data is organised in: {Course name}/{SCORM activity name}/{My attempts}/{Attempt X}/data.json // where X is the attempt number. - array_walk($alldata, function($attemptsdata, $contextid) use ($subcontext) { + array_walk($alldata, function($attemptsdata, $contextid) { $context = \context::instance_by_id($contextid); - array_walk($attemptsdata, function($data, $attempt) use ($context, $subcontext) { - writer::with_context($context)->export_related_data( + array_walk($attemptsdata, function($data, $attempt) use ($context) { + $subcontext = [ + get_string('myattempts', 'scorm'), + get_string('attempt', 'scorm'). " $attempt" + ]; + writer::with_context($context)->export_data( $subcontext, - 'attempt-'.$attempt, (object)['scoestrack' => $data] ); }); @@ -209,13 +211,15 @@ class provider implements } $aiccsessions->close(); - // The aicc_session data is organised in: {Course name}/{SCORM activity name}/aiccsession.json. + // The aicc_session data is organised in: {Course name}/{SCORM activity name}/{My AICC sessions}/data.json // In this case, the attempt hasn't been included in the json file because it can be null. array_walk($alldata, function($data, $contextid) { $context = \context::instance_by_id($contextid); - writer::with_context($context)->export_related_data( - [], - 'aiccsession', + $subcontext = [ + get_string('myaiccsessions', 'scorm') + ]; + writer::with_context($context)->export_data( + $subcontext, (object)['sessions' => $data] ); }); diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index c541a076ee0..c693dc36c2f 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -208,6 +208,8 @@ $string['interactions'] = 'Interactions'; $string['masteryoverride'] = 'Mastery score overrides status'; $string['masteryoverride_help'] = 'If enabled and a mastery score is provided, when LMSFinish is called and a raw score has been set, status will be recalculated using the raw score and mastery score and any status provided by the SCORM (including "incomplete") will be overridden.'; $string['masteryoverridedesc'] = 'This preference sets the default for the mastery score override setting'; +$string['myattempts'] = 'My attempts'; +$string['myaiccsessions'] = 'My AICC sessions'; $string['repositorynotsupported'] = 'This repository does not support linking directly to an imsmanifest.xml file.'; $string['trackid'] = 'Id'; $string['trackid_help'] = 'This is the identifier set by your SCORM package for this question, the SCORM specification doesn\'t allow the full question text to be provided.'; diff --git a/mod/scorm/tests/privacy_test.php b/mod/scorm/tests/privacy_test.php index aac9d89fec7..00811b78d1f 100644 --- a/mod/scorm/tests/privacy_test.php +++ b/mod/scorm/tests/privacy_test.php @@ -81,9 +81,16 @@ class mod_scorm_testcase extends provider_testcase { $writer = writer::with_context($this->context); $this->export_context_data_for_user($this->student0->id, $this->context, 'mod_scorm'); - $data = $writer->get_related_data([], 'attempt-1'); + $subcontextattempt1 = [ + get_string('myattempts', 'scorm'), + get_string('attempt', 'scorm'). " 1" + ]; + $subcontextaicc = [ + get_string('myaiccsessions', 'scorm') + ]; + $data = $writer->get_data($subcontextattempt1); $this->assertEmpty($data); - $data = $writer->get_related_data([], 'aiccsession'); + $data = $writer->get_data($subcontextaicc); $this->assertEmpty($data); // Validate exported data for student1. @@ -96,16 +103,24 @@ class mod_scorm_testcase extends provider_testcase { $data = $writer->get_data([]); $this->assertEquals('SCORM1', $data->name); - $data = $writer->get_related_data([], 'attempt-1'); + $data = $writer->get_data($subcontextattempt1); $this->assertCount(1, (array) $data); $this->assertCount(2, (array) reset($data)); - $data = $writer->get_related_data([], 'attempt-2'); + $subcontextattempt2 = [ + get_string('myattempts', 'scorm'), + get_string('attempt', 'scorm'). " 2" + ]; + $data = $writer->get_data($subcontextattempt2); $this->assertCount(2, (array) reset($data)); // The student1 has only 2 scoes_track attempts. - $data = $writer->get_related_data([], 'attempt-3'); + $subcontextattempt3 = [ + get_string('myattempts', 'scorm'), + get_string('attempt', 'scorm'). " 3" + ]; + $data = $writer->get_data($subcontextattempt3); $this->assertEmpty($data); // The student1 has only 1 aicc_session. - $data = $writer->get_related_data([], 'aiccsession'); + $data = $writer->get_data($subcontextaicc); $this->assertCount(1, (array) $data); }