MDL-62449 scorm: Add SCORM data to privacy export (name, description)

This commit is contained in:
Sara Arjona 2018-05-16 08:51:36 +02:00
parent 9e7c397889
commit cd3ef1fbc4
2 changed files with 23 additions and 9 deletions

View 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,19 @@ 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.
$subcontext = [];
list($insql, $inparams) = $DB->get_in_or_equal($contexts, SQL_PARAMS_NAMED);
$sql = "SELECT ss.id,
ss.attempt,
ss.element,
@ -154,11 +164,11 @@ class provider implements
// The scoes_track data is organised in: {Course name}/{SCORM activity name}/attempt-X.json.
// where X is the attempt number.
array_walk($alldata, function($attemptsdata, $contextid) {
array_walk($alldata, function($attemptsdata, $contextid) use ($subcontext) {
$context = \context::instance_by_id($contextid);
array_walk($attemptsdata, function($data, $attempt) use ($context) {
array_walk($attemptsdata, function($data, $attempt) use ($context, $subcontext) {
writer::with_context($context)->export_related_data(
[],
$subcontext,
'attempt-'.$attempt,
(object)['scoestrack' => $data]
);

View File

@ -79,10 +79,10 @@ 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');
$this->assertEmpty($data);
$this->export_context_data_for_user($this->student0->id, $this->context, 'mod_scorm');
$data = $writer->get_related_data([], 'aiccsession');
$this->assertEmpty($data);
@ -92,6 +92,10 @@ 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_data([]);
$this->assertEquals('SCORM1', $data->name);
$data = $writer->get_related_data([], 'attempt-1');
$this->assertCount(1, (array) $data);
$this->assertCount(2, (array) reset($data));
@ -101,7 +105,6 @@ class mod_scorm_testcase extends provider_testcase {
$data = $writer->get_related_data([], 'attempt-3');
$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');
$this->assertCount(1, (array) $data);
}
@ -189,7 +192,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.