Merge branch 'MDL-62449-master' of git://github.com/sarjona/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 19 Jun 2018 16:18:51 +0000 (18:18 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 19 Jun 2018 16:18:51 +0000 (18:18 +0200)
mod/scorm/classes/privacy/provider.php
mod/scorm/lang/en/scorm.php
mod/scorm/tests/privacy_test.php

index 855499e..3d6c1c7 100644 (file)
@@ -27,8 +27,9 @@ namespace mod_scorm\privacy;
 defined('MOODLE_INTERNAL') || die();
 
 use core_privacy\local\metadata\collection;
-use core_privacy\local\request\contextlist;
 use core_privacy\local\request\approved_contextlist;
+use core_privacy\local\request\contextlist;
+use core_privacy\local\request\helper;
 use core_privacy\local\request\transform;
 use core_privacy\local\request\writer;
 
@@ -122,10 +123,18 @@ class provider implements
             return;
         }
 
-        $userid = $contextlist->get_user()->id;
-        list($insql, $inparams) = $DB->get_in_or_equal($contexts, SQL_PARAMS_NAMED);
+        $user = $contextlist->get_user();
+        $userid = $user->id;
+        // Get SCORM data.
+        foreach ($contexts as $contextid) {
+            $context = \context::instance_by_id($contextid);
+            $data = helper::get_context_data($context, $user);
+            writer::with_context($context)->export_data([], $data);
+            helper::export_context_files($context, $user);
+        }
 
         // Get scoes_track data.
+        list($insql, $inparams) = $DB->get_in_or_equal($contexts, SQL_PARAMS_NAMED);
         $sql = "SELECT ss.id,
                        ss.attempt,
                        ss.element,
@@ -152,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) {
             $context = \context::instance_by_id($contextid);
             array_walk($attemptsdata, function($data, $attempt) use ($context) {
-                writer::with_context($context)->export_related_data(
-                    [],
-                    'attempt-'.$attempt,
+                $subcontext = [
+                    get_string('myattempts', 'scorm'),
+                    get_string('attempt', 'scorm'). " $attempt"
+                ];
+                writer::with_context($context)->export_data(
+                    $subcontext,
                     (object)['scoestrack' => $data]
                 );
             });
@@ -199,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 096988d..00811b7 100644 (file)
@@ -79,11 +79,18 @@ class mod_scorm_testcase extends provider_testcase {
         // Validate exported data for student0 (without any AICC/SCORM attempt).
         $this->setUser($this->student0);
         $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);
-        $this->export_context_data_for_user($this->student0->id, $this->context, 'mod_scorm');
-        $data = $writer->get_related_data([], 'aiccsession');
+        $data = $writer->get_data($subcontextaicc);
         $this->assertEmpty($data);
 
         // Validate exported data for student1.
@@ -92,17 +99,28 @@ class mod_scorm_testcase extends provider_testcase {
         $writer = writer::with_context($this->context);
         $this->assertFalse($writer->has_any_data());
         $this->export_context_data_for_user($this->student1->id, $this->context, 'mod_scorm');
-        $data = $writer->get_related_data([], 'attempt-1');
+
+        $data = $writer->get_data([]);
+        $this->assertEquals('SCORM1', $data->name);
+
+        $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.
-        $this->export_context_data_for_user($this->student1->id, $this->context, 'mod_scorm');
-        $data = $writer->get_related_data([], 'aiccsession');
+        $data = $writer->get_data($subcontextaicc);
         $this->assertCount(1, (array) $data);
     }
 
@@ -189,7 +207,8 @@ class mod_scorm_testcase extends provider_testcase {
 
         // Setup test data.
         $course = $this->getDataGenerator()->create_course();
-        $scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id));
+        $params = array('course' => $course->id, 'name' => 'SCORM1');
+        $scorm = $this->getDataGenerator()->create_module('scorm', $params);
         $this->context = \context_module::instance($scorm->cmid);
 
         // Users enrolments.