From 9d227990e8defb514f80fef8e6a2824b44ae610d Mon Sep 17 00:00:00 2001 From: Rastislav Chynoransky Date: Tue, 26 Mar 2024 09:35:21 +0100 Subject: [PATCH] [harvest] work type fallback --- app/Harvest/Mappers/GmuhkItemMapper.php | 29 ++++++++++++++----- tests/Harvest/Mappers/GmuhkItemMapperTest.php | 13 +++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/Harvest/Mappers/GmuhkItemMapper.php b/app/Harvest/Mappers/GmuhkItemMapper.php index 578591f10..42a1b6961 100644 --- a/app/Harvest/Mappers/GmuhkItemMapper.php +++ b/app/Harvest/Mappers/GmuhkItemMapper.php @@ -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', @@ -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]); @@ -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); } diff --git a/tests/Harvest/Mappers/GmuhkItemMapperTest.php b/tests/Harvest/Mappers/GmuhkItemMapperTest.php index 92e809f04..391d9f2bc 100644 --- a/tests/Harvest/Mappers/GmuhkItemMapperTest.php +++ b/tests/Harvest/Mappers/GmuhkItemMapperTest.php @@ -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')); + } }