Support multiple provided URLs

An object might have more then a single URL.
This is now added.
This commit is contained in:
Daniel Siepmann 2021-08-31 08:10:46 +02:00
parent 8315d42934
commit 265cb27236
4 changed files with 64 additions and 9 deletions

View file

@ -53,9 +53,9 @@ abstract class Minimum
/**
* URL to official version of this thing outside of ThüCAT.
*
* @var string
* @var string[]
*/
protected $url = '';
protected $urls = [];
public function getId(): string
{
@ -77,9 +77,9 @@ abstract class Minimum
return $this->description;
}
public function getUrl(): string
public function getUrls(): array
{
return $this->url;
return $this->urls;
}
/**
@ -108,10 +108,14 @@ abstract class Minimum
/**
* @internal for mapping via Symfony component.
* @param string|array $url
*/
public function setUrl(string $url): void
public function setUrl($url): void
{
$this->url = $url;
if (is_string($url)) {
$url = [$url];
}
$this->urls = $url;
}
public static function getPriority(): int

View file

@ -325,7 +325,7 @@ class GeneralConverter implements Converter
'type' => $mediaObject->getType(),
'title' => $mediaObject->getName(),
'description' => $mediaObject->getDescription(),
'url' => $mediaObject->getUrl(),
'url' => $mediaObject->getUrls()[0] ?? '',
'copyrightYear' => $mediaObject->getCopyrightYear(),
'license' => [
'type' => $mediaObject->getLicense(),

View file

@ -68,7 +68,7 @@ class BaseInfosTest extends TestCase
self::assertSame('', $result->getId());
self::assertSame('', $result->getName());
self::assertSame('', $result->getDescription());
self::assertSame('', $result->getUrl());
self::assertSame([], $result->getUrls());
self::assertNull($result->getPhoto());
self::assertSame([], $result->getImages());
self::assertNull($result->getManagedBy());
@ -94,7 +94,7 @@ class BaseInfosTest extends TestCase
self::assertSame('https://thuecat.org/resources/835224016581-dara', $result->getId());
self::assertSame('The name of the Thing', $result->getName());
self::assertSame('This is some long description describing this Thing.', $result->getDescription());
self::assertSame('https://example.com/the-thing', $result->getUrl());
self::assertSame(['https://example.com/the-thing'], $result->getUrls());
}
/**

View file

@ -236,4 +236,55 @@ class PlaceInfosTest extends TestCase
self::assertSame('', $result->getAddress()->getFaxNumber());
self::assertSame('dominformation@domberg-erfurt.de', $result->getAddress()->getEmail());
}
/**
* @test
*/
public function mapsIncomingMultipleUrls(): void
{
$subject = new EntityMapper();
$result = $subject->mapDataToEntity([
'schema:url' => [
0 => [
'@type' => 'schema:URL',
'@value' => 'https://example.com/1',
],
1 => [
'@type' => 'schema:URL',
'@value' => 'https://example.com/2',
],
],
], Place::class, [
JsonDecode::ACTIVE_LANGUAGE => 'de',
]);
self::assertInstanceOf(Place::class, $result);
self::assertSame([
'https://example.com/1',
'https://example.com/2',
], $result->getUrls());
}
/**
* @test
*/
public function mapsIncomingSingleUrl(): void
{
$subject = new EntityMapper();
$result = $subject->mapDataToEntity([
'schema:url' => [
'@type' => 'schema:URL',
'@value' => 'https://example.com/1',
],
], Place::class, [
JsonDecode::ACTIVE_LANGUAGE => 'de',
]);
self::assertInstanceOf(Place::class, $result);
self::assertSame([
'https://example.com/1',
], $result->getUrls());
}
}