Skip to content

Commit

Permalink
Merge branch 'MDL-62449-master' of git://github.com/sarjona/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 19, 2018
2 parents fa6f911 + 1d76dd7 commit 3a55517
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
36 changes: 25 additions & 11 deletions mod/scorm/classes/privacy/provider.php
Expand Up @@ -27,8 +27,9 @@
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;

Expand Down Expand Up @@ -122,10 +123,18 @@ public static function export_user_data(approved_contextlist $contextlist) {
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,
Expand All @@ -152,14 +161,17 @@ public static function export_user_data(approved_contextlist $contextlist) {
}
$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]
);
});
Expand Down Expand Up @@ -199,13 +211,15 @@ public static function export_user_data(approved_contextlist $contextlist) {
}
$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]
);
});
Expand Down
2 changes: 2 additions & 0 deletions mod/scorm/lang/en/scorm.php
Expand Up @@ -208,6 +208,8 @@
$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.';
Expand Down
37 changes: 28 additions & 9 deletions mod/scorm/tests/privacy_test.php
Expand Up @@ -79,11 +79,18 @@ public function test_export_user_data() {
// 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.
Expand All @@ -92,17 +99,28 @@ public function test_export_user_data() {
$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);
}

Expand Down Expand Up @@ -189,7 +207,8 @@ protected function scorm_setup_test_scenario_data() {

// 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.
Expand Down

0 comments on commit 3a55517

Please sign in to comment.