MDL-62449 scorm: Move related data to data in the privacy export
authorSara Arjona <sara@moodle.com>
Wed, 16 May 2018 08:18:55 +0000 (10:18 +0200)
committerSara Arjona <sara@moodle.com>
Mon, 18 Jun 2018 08:42:26 +0000 (10:42 +0200)
mod/scorm/classes/privacy/provider.php
mod/scorm/lang/en/scorm.php
mod/scorm/tests/privacy_test.php

index 72cdb3d..3d6c1c7 100644 (file)
@@ -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]
             );
         });
index c541a07..c693dc3 100644 (file)
@@ -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.';
index aac9d89..00811b7 100644 (file)
@@ -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);
     }