Skip to content

Commit 1943c6e

Browse files
committed
add edlibVersionId lti-dl extension
1 parent ea58a48 commit 1943c6e

6 files changed

+30
-0
lines changed

src/Lti/Edlib/DeepLinking/EdlibContentItemMapper.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function map(array $data): ContentItem
3232
url: $item->getUrl(),
3333
custom: $item->getCustom(),
3434
))
35+
->withEdlibVersionId(Prop::getOfType($data, 'edlibVersionId', Prop::TYPE_NORMALIZED_STRING))
3536
->withLanguageIso639_3(Prop::getOfType($data, 'languageIso639_3', Prop::TYPE_NORMALIZED_STRING))
3637
->withLicense(Prop::getOfType($data, 'license', Prop::TYPE_NORMALIZED_STRING))
3738
->withPublished(Prop::getOfType($data, 'published', Prop::TYPE_BOOLEAN))

src/Lti/Edlib/DeepLinking/EdlibContentItemsSerializer.php

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
private const CONTEXT = [
1313
'edlib' => 'https://spec.edlib.com/lti/vocab#',
1414
'xs' => 'http://www.w3.org/2001/XMLSchema#',
15+
'edlibVersionId' => [
16+
'@id' => 'edlib:edlibVersionId',
17+
'@type' => 'xs:normalizedString',
18+
],
1519
'languageIso639_3' => [
1620
'@id' => 'edlib:languageIso639_3',
1721
'@type' => 'xs:normalizedString',

src/Lti/Edlib/DeepLinking/EdlibLtiLinkItem.php

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class EdlibLtiLinkItem extends LtiLinkItem
1212
{
13+
private string|null $edlibVersionId = null;
14+
1315
private string|null $languageIso639_3 = null;
1416

1517
private string|null $license = null;
@@ -23,6 +25,19 @@ class EdlibLtiLinkItem extends LtiLinkItem
2325
*/
2426
private array $tags = [];
2527

28+
public function getEdlibVersionId(): string|null
29+
{
30+
return $this->edlibVersionId;
31+
}
32+
33+
public function withEdlibVersionId(string|null $edlibVersionId): static
34+
{
35+
$self = clone $this;
36+
$self->edlibVersionId = $edlibVersionId;
37+
38+
return $self;
39+
}
40+
2641
public function getLanguageIso639_3(): string|null
2742
{
2843
return $this->languageIso639_3;

src/Lti/Edlib/DeepLinking/EdlibLtiLinkItemSerializer.php

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public function serialize(LtiLinkItem $item): array
2020
$serialized = $this->serializer->serialize($item);
2121

2222
if ($item instanceof EdlibLtiLinkItem) {
23+
if ($item->getEdlibVersionId() !== null) {
24+
$serialized['edlibVersionId'] = $item->getEdlibVersionId();
25+
}
26+
2327
if ($item->getLicense() !== null) {
2428
$serialized['license'] = $item->getLicense();
2529
}

tests/Lti/Edlib/EdlibContentItemMapperTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function testMapsEdlibExtensions(): void
2828
'mediaType' => 'application/vnd.ims.lti.v1.ltilink',
2929
'title' => 'My Cool LTI Content',
3030
'url' => 'https://example.com/my-lti-content',
31+
'edlibVersionId' => '9876543210',
3132
'languageIso639_3' => 'eng',
3233
'license' => 'MIT',
3334
'published' => true,
@@ -41,6 +42,7 @@ public function testMapsEdlibExtensions(): void
4142
$this->assertArrayHasKey(0, $items);
4243
$this->assertInstanceOf(EdlibLtiLinkItem::class, $items[0]);
4344
$this->assertSame('My Cool LTI Content', $items[0]->getTitle());
45+
$this->assertSame('9876543210', $items[0]->getEdlibVersionId());
4446
$this->assertSame('eng', $items[0]->getLanguageIso639_3());
4547
$this->assertSame('MIT', $items[0]->getLicense());
4648
$this->assertFalse($items[0]->isShared());

tests/Lti/Edlib/EdlibContentItemsSerializerTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function testAddsJsonldContextAndSerializesEdlibExtensions(): void
1919
{
2020
$data = $this->serializer->serialize([
2121
(new EdlibLtiLinkItem(title: 'Foo'))
22+
->withEdlibVersionId('1234567890')
2223
->withLanguageIso639_3('eng')
2324
->withLicense('MIT')
2425
->withPublished(false)
@@ -41,6 +42,9 @@ public function testAddsJsonldContextAndSerializesEdlibExtensions(): void
4142
$this->assertArrayHasKey(0, $data['@graph']);
4243
$this->assertIsArray($data['@graph'][0]);
4344

45+
$this->assertArrayHasKey('edlibVersionId', $data['@graph'][0]);
46+
$this->assertSame('1234567890', $data['@graph'][0]['edlibVersionId']);
47+
4448
$this->assertArrayHasKey('languageIso639_3', $data['@graph'][0]);
4549
$this->assertSame('eng', $data['@graph'][0]['languageIso639_3']);
4650

0 commit comments

Comments
 (0)