Skip to content

Commit

Permalink
Merge pull request #981 from SlovakNationalGallery/WEBUMENIA-2071-fal…
Browse files Browse the repository at this point in the history
…lback

[harvest] work type fallback
  • Loading branch information
rastislav-chynoransky authored Mar 26, 2024
2 parents 06d474d + 9d22799 commit 39c9e0e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
29 changes: 21 additions & 8 deletions app/Harvest/Mappers/GmuhkItemMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ class GmuhkItemMapper extends AbstractMapper

protected $modelClass = Item::class;

public function __construct()
{
parent::__construct();
$this->mediumTranslationKeys = array_flip(trans('item.media', locale: 'cs'));
$this->techniqueTranslationKeys = array_flip(trans('item.techniques', locale: 'cs'));
}

protected array $workTypeTranslationKeys = [
'publikacePredmetu:GMUHK:151:F' => 'fotografia',
'publikacePredmetu:GMUHK:151:F:Fo' => 'fotografia',
Expand All @@ -36,6 +29,23 @@ public function __construct()
'publikacePredmetu:SKT:2021:SKT:So' => 'sochárstvo',
];

protected array $fallbackWorkTypeTranslationKeys = [
'F' => 'fotografia',
'G' => 'grafika',
'K' => 'kresba',
'O' => 'maliarstvo',
'P' => 'sochárstvo/plastika',
'VA' => 'iné médiá/video',
'GVP' => 'sochárstvo/skulptúra',
];

public function __construct()
{
parent::__construct();
$this->mediumTranslationKeys = array_flip(trans('item.media', locale: 'cs'));
$this->techniqueTranslationKeys = array_flip(trans('item.techniques', locale: 'cs'));
}

public function mapId(array $row): string
{
$matches = $this->parseIdentifier($row['id'][0]);
Expand All @@ -61,7 +71,10 @@ public function mapMeasurement(array $row, string $locale): ?string

public function mapWorkType(array $row, $locale)
{
$key = $this->workTypeTranslationKeys[$row['work_type'][0]];
$parsedId = $this->parseIdentifier($row['id'][0]);
$key = $this->workTypeTranslationKeys[$row['work_type'][0]]
?? $this->fallbackWorkTypeTranslationKeys[$parsedId['work_type']];

return trans("item.work_types.$key", locale: $locale);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Harvest/Mappers/GmuhkItemMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,17 @@ public function testMap()
];
$this->assertEquals($expected, $mapped);
}

public function testMapWorkTypeFallback()
{
$mapper = new GmuhkItemMapper();
$row = [
'id' => ['oai:khk.museion.cz:GMUHK~publikacePredmetu~G0259'],
'work_type' => ['publikacePredmetu:GMUHK:151'],
];

$this->assertEquals('grafika', $mapper->mapWorkType($row, 'sk'));
$this->assertEquals('grafika', $mapper->mapWorkType($row, 'cs'));
$this->assertEquals('graphics', $mapper->mapWorkType($row, 'en'));
}
}

0 comments on commit 39c9e0e

Please sign in to comment.