MDL-64702 badges: Add to privacy
Add endorsement, related badges and alignment to privacy export.
This commit is contained in:
@@ -82,6 +82,23 @@ class provider implements
|
||||
'datemet' => 'privacy:metadata:criteriamet:datemet',
|
||||
], 'privacy:metadata:criteriamet');
|
||||
|
||||
$collection->add_database_table('badge_endorsement', [
|
||||
'issuername' => 'privacy:metadata:endorsement:issuername',
|
||||
'issuerurl' => 'privacy:metadata:endorsement:issuerurl',
|
||||
'issueremail' => 'privacy:metadata:endorsement:issueremail',
|
||||
'claimid' => 'privacy:metadata:endorsement:claimid',
|
||||
'claimcomment' => 'privacy:metadata:endorsement:claimcomment',
|
||||
'dateissued' => 'privacy:metadata:endorsement:dateissued',
|
||||
], 'privacy:metadata:endorsement');
|
||||
|
||||
$collection->add_database_table('badge_competencies', [
|
||||
'targetname' => 'privacy:metadata:alignment:targetname',
|
||||
'targeturl' => 'privacy:metadata:alignment:targeturl',
|
||||
'targetdescription' => 'privacy:metadata:alignment:targetdescription',
|
||||
'targetframework' => 'privacy:metadata:alignment:targetframework',
|
||||
'targetcode' => 'privacy:metadata:alignment:targetcode',
|
||||
], 'privacy:metadata:alignment');
|
||||
|
||||
$collection->add_database_table('badge_manual_award', [
|
||||
'recipientid' => 'privacy:metadata:manualaward:recipientid',
|
||||
'issuerid' => 'privacy:metadata:manualaward:issuerid',
|
||||
@@ -376,18 +393,40 @@ class provider implements
|
||||
|
||||
// Export the badges.
|
||||
$uniqueid = $DB->sql_concat_join("'-'", ['b.id', 'COALESCE(bc.id, 0)', 'COALESCE(bi.id, 0)',
|
||||
'COALESCE(bma.id, 0)', 'COALESCE(bcm.id, 0)']);
|
||||
'COALESCE(bma.id, 0)', 'COALESCE(bcm.id, 0)', 'COALESCE(ba.id, 0)']);
|
||||
$sql = "
|
||||
SELECT $uniqueid AS uniqueid, b.id,
|
||||
bi.id AS biid, bi.dateissued, bi.dateexpire, bi.uniquehash,
|
||||
bma.id AS bmaid, bma.datemet, bma.issuerid,
|
||||
bcm.id AS bcmid,
|
||||
c.fullname AS coursename,
|
||||
be.id AS beid,
|
||||
be.issuername AS beissuername,
|
||||
be.issuerurl AS beissuerurl,
|
||||
be.issueremail AS beissueremail,
|
||||
be.claimid AS beclaimid,
|
||||
be.claimcomment AS beclaimcomment,
|
||||
be.dateissued AS bedateissued,
|
||||
brb.id as rbid,
|
||||
brb.badgeid as rbbadgeid,
|
||||
brb.relatedbadgeid as rbrelatedbadgeid,
|
||||
ba.id as baid,
|
||||
ba.targetname as batargetname,
|
||||
ba.targeturl as batargeturl,
|
||||
ba.targetdescription as batargetdescription,
|
||||
ba.targetframework as batargetframework,
|
||||
ba.targetcode as batargetcode,
|
||||
$ctxfields
|
||||
FROM {badge} b
|
||||
LEFT JOIN {badge_issued} bi
|
||||
ON bi.badgeid = b.id
|
||||
AND bi.userid = :userid1
|
||||
LEFT JOIN {badge_related} brb
|
||||
ON ( b.id = brb.badgeid OR b.id = brb.relatedbadgeid )
|
||||
LEFT JOIN {badge_competencies} ba
|
||||
ON ( b.id = ba.badgeid )
|
||||
LEFT JOIN {badge_endorsement} be
|
||||
ON be.badgeid = b.id
|
||||
LEFT JOIN {badge_manual_award} bma
|
||||
ON bma.badgeid = b.id
|
||||
AND bma.recipientid = :userid2
|
||||
@@ -421,15 +460,32 @@ class provider implements
|
||||
if ($carry === null) {
|
||||
$carry = [
|
||||
'name' => $badge->name,
|
||||
'version' => $badge->version,
|
||||
'language' => $badge->language,
|
||||
'imageauthorname' => $badge->imageauthorname,
|
||||
'imageauthoremail' => $badge->imageauthoremail,
|
||||
'imageauthorurl' => $badge->imageauthorurl,
|
||||
'imagecaption' => $badge->imagecaption,
|
||||
'issued' => null,
|
||||
'manual_award' => null,
|
||||
'criteria_met' => []
|
||||
'criteria_met' => [],
|
||||
'endorsement' => null,
|
||||
];
|
||||
|
||||
if ($badge->type == BADGE_TYPE_COURSE) {
|
||||
context_helper::preload_from_record($record);
|
||||
$carry['course'] = format_string($record->coursename, true, ['context' => $badge->get_context()]);
|
||||
}
|
||||
if (!empty($record->beid)) {
|
||||
$carry['endorsement'] = [
|
||||
'issuername' => $record->beissuername,
|
||||
'issuerurl' => $record->beissuerurl,
|
||||
'issueremail' => $record->beissueremail,
|
||||
'claimid' => $record->beclaimid,
|
||||
'claimcomment' => $record->beclaimcomment,
|
||||
'dateissued' => $record->bedateissued ? transform::datetime($record->bedateissued) : null
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($record->biid)) {
|
||||
$carry['issued'] = [
|
||||
@@ -446,6 +502,52 @@ class provider implements
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!empty($record->rbid)) {
|
||||
if (empty($carry['related_badge'])) {
|
||||
$carry['related_badge'] = [];
|
||||
}
|
||||
$rbid = $record->rbbadgeid;
|
||||
if ($rbid == $record->id) {
|
||||
$rbid = $record->rbrelatedbadgeid;
|
||||
}
|
||||
$exists = false;
|
||||
foreach ($carry['related_badge'] as $related) {
|
||||
if ($related['badgeid'] == $rbid) {
|
||||
$exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$exists) {
|
||||
$relatedbadge = new badge($rbid);
|
||||
$carry['related_badge'][] = [
|
||||
'badgeid' => $rbid,
|
||||
'badgename' => $relatedbadge->name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($record->baid)) {
|
||||
if (empty($carry['alignment'])) {
|
||||
$carry['alignment'] = [];
|
||||
}
|
||||
$exists = false;
|
||||
$newalignment = [
|
||||
'targetname' => $record->batargetname,
|
||||
'targeturl' => $record->batargeturl,
|
||||
'targetdescription' => $record->batargetdescription,
|
||||
'targetframework' => $record->batargetframework,
|
||||
'targetcode' => $record->batargetcode,
|
||||
];
|
||||
foreach ($carry['alignment'] as $alignment) {
|
||||
if ($alignment == $newalignment) {
|
||||
$exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$exists) {
|
||||
$carry['alignment'][] = $newalignment;
|
||||
}
|
||||
}
|
||||
|
||||
// Export the details of the criteria met.
|
||||
// We only do that once, when we find that a least one criteria was met.
|
||||
|
||||
@@ -306,7 +306,11 @@ class core_badges_privacy_testcase extends provider_testcase {
|
||||
$u2ctx = context_user::instance($u2->id);
|
||||
|
||||
$b1 = $this->create_badge(['usercreated' => $u3->id]);
|
||||
$this->endorse_badge(['badgeid' => $b1->id]);
|
||||
$this->align_badge(['badgeid' => $b1->id], ' (1)');
|
||||
$this->align_badge(['badgeid' => $b1->id], ' (2)');
|
||||
$b2 = $this->create_badge(['type' => BADGE_TYPE_COURSE, 'courseid' => $c1->id, 'usermodified' => $u3->id]);
|
||||
$this->relate_badge($b1->id, $b2->id);
|
||||
$b3 = $this->create_badge();
|
||||
$b3crit = $this->create_criteria_manual($b3->id);
|
||||
$b4 = $this->create_badge();
|
||||
@@ -333,6 +337,12 @@ class core_badges_privacy_testcase extends provider_testcase {
|
||||
$path = [get_string('badges', 'core_badges'), "{$b1->name} ({$b1->id})"];
|
||||
$data = writer::with_context($u1ctx)->get_data($path);
|
||||
$this->assertEquals($b1->name, $data->name);
|
||||
$this->assertEquals($b1->version, $data->version);
|
||||
$this->assertEquals($b1->language, $data->language);
|
||||
$this->assertEquals($b1->imageauthorname, $data->imageauthorname);
|
||||
$this->assertEquals($b1->imageauthoremail, $data->imageauthoremail);
|
||||
$this->assertEquals($b1->imageauthorurl, $data->imageauthorurl);
|
||||
$this->assertEquals($b1->imagecaption, $data->imagecaption);
|
||||
$this->assertNotEmpty($data->issued);
|
||||
$this->assertEmpty($data->manual_award);
|
||||
$this->assertEmpty($data->criteria_met);
|
||||
@@ -340,6 +350,33 @@ class core_badges_privacy_testcase extends provider_testcase {
|
||||
$this->assertEquals('yoohoo', $data->issued['unique_hash']);
|
||||
$this->assertNull($data->issued['expires_on']);
|
||||
|
||||
$this->assertNotEmpty($data->endorsement);
|
||||
$this->assertNotEmpty($data->endorsement['issuername']);
|
||||
$this->assertNotEmpty($data->endorsement['issuerurl']);
|
||||
$this->assertNotEmpty($data->endorsement['issueremail']);
|
||||
$this->assertNotEmpty($data->endorsement['claimid']);
|
||||
$this->assertNotEmpty($data->endorsement['claimcomment']);
|
||||
$this->assertNotEmpty($data->endorsement['dateissued']);
|
||||
|
||||
$this->assertNotEmpty($data->related_badge);
|
||||
$this->assertNotEmpty($data->related_badge[0]);
|
||||
$this->assertEquals($data->related_badge[0]['badgeid'], $b2->id);
|
||||
$this->assertEquals($data->related_badge[0]['badgename'], $b2->name);
|
||||
|
||||
$this->assertNotEmpty($data->alignment);
|
||||
$this->assertNotEmpty($data->alignment[0]);
|
||||
$this->assertNotEmpty($data->alignment[0]['targetname']);
|
||||
$this->assertNotEmpty($data->alignment[0]['targeturl']);
|
||||
$this->assertNotEmpty($data->alignment[0]['targetdescription']);
|
||||
$this->assertNotEmpty($data->alignment[0]['targetframework']);
|
||||
$this->assertNotEmpty($data->alignment[0]['targetcode']);
|
||||
$this->assertNotEmpty($data->alignment[1]);
|
||||
$this->assertNotEmpty($data->alignment[1]['targetname']);
|
||||
$this->assertNotEmpty($data->alignment[1]['targeturl']);
|
||||
$this->assertNotEmpty($data->alignment[1]['targetdescription']);
|
||||
$this->assertNotEmpty($data->alignment[1]['targetframework']);
|
||||
$this->assertNotEmpty($data->alignment[1]['targetcode']);
|
||||
|
||||
$path = [get_string('badges', 'core_badges'), "{$b2->name} ({$b2->id})"];
|
||||
$data = writer::with_context($u1ctx)->get_data($path);
|
||||
$this->assertEquals($b2->name, $data->name);
|
||||
@@ -598,12 +635,78 @@ class core_badges_privacy_testcase extends provider_testcase {
|
||||
'attachment' => 1,
|
||||
'notification' => 0,
|
||||
'status' => BADGE_STATUS_ACTIVE,
|
||||
'version' => OPEN_BADGES_V2,
|
||||
'language' => 'en',
|
||||
'imageauthorname' => 'Image author',
|
||||
'imageauthoremail' => '[email protected]',
|
||||
'imageauthorurl' => 'http://image.example.com/',
|
||||
'imagecaption' => 'Image caption'
|
||||
], $params);
|
||||
$record->id = $DB->insert_record('badge', $record);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relate a badge.
|
||||
*
|
||||
* @param array $params Parameters.
|
||||
* @return object
|
||||
*/
|
||||
protected function relate_badge(int $badgeid, int $relatedbadgeid) {
|
||||
global $DB;
|
||||
$record = (object) [
|
||||
'badgeid' => $badgeid,
|
||||
'relatedbadgeid' => $relatedbadgeid
|
||||
];
|
||||
$record->id = $DB->insert_record('badge_related', $record);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Align a badge.
|
||||
*
|
||||
* @param array $params Parameters.
|
||||
* @param string $suffix Option to append to strings.
|
||||
* @return object
|
||||
*/
|
||||
protected function align_badge(array $params = [], $suffix = '') {
|
||||
global $DB;
|
||||
$record = (object) array_merge([
|
||||
'badgeid' => null,
|
||||
'targetname' => "Alignment name" . $suffix,
|
||||
'targeturl' => "http://issuer-url.domain.co.nz",
|
||||
'targetdescription' => "Description" . $suffix,
|
||||
'targetframework' => "Framework" . $suffix,
|
||||
'targetcode' => "Code" . $suffix
|
||||
], $params);
|
||||
$record->id = $DB->insert_record('badge_competencies', $record);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Endorse a badge.
|
||||
*
|
||||
* @param array $params Parameters.
|
||||
* @return object
|
||||
*/
|
||||
protected function endorse_badge(array $params = []) {
|
||||
global $DB, $USER;
|
||||
$record = (object) array_merge([
|
||||
'issuername' => "External issuer name",
|
||||
'issuerurl' => "http://issuer-url.domain.co.nz",
|
||||
'issueremail' => "[email protected]",
|
||||
'claimid' => "Claim ID",
|
||||
'claimcomment' => "Claim comment",
|
||||
'dateissued' => time()
|
||||
], $params);
|
||||
$record->id = $DB->insert_record('badge_endorsement', $record);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a backpack.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user