-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #929 from SlovakNationalGallery/MG-13
[import] mg foto importer
- Loading branch information
Showing
10 changed files
with
635 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
|
||
namespace App\Importers; | ||
|
||
use App\Item; | ||
use Illuminate\Support\Arr; | ||
|
||
class MgFotoImporter extends AbstractImporter | ||
{ | ||
use MgImporterTrait; | ||
|
||
protected static $options = [ | ||
'delimiter' => ';', | ||
'enclosure' => '"', | ||
'escape' => '\\', | ||
'newline' => "\r\n", | ||
'input_encoding' => 'CP1250', | ||
]; | ||
|
||
protected $defaults = [ | ||
'author' => 'neurčený autor', // todo translatable author | ||
'gallery:sk' => 'Moravská galerie, MG', | ||
'gallery:cs' => 'Moravská galerie, MG', | ||
]; | ||
|
||
protected $mapping = [ | ||
'date_earliest' => 'RokVzOd', | ||
'date_latest' => 'RokVzDo', | ||
'acquisition_date' => 'RokAkv', | ||
'author' => 'Autor', | ||
'dating:sk' => 'DatVz', | ||
'dating:cs' => 'DatVz', | ||
// 'location:sk' => 'AktLokace', todo | ||
// 'location:cs' => 'AktLokace', todo | ||
'description:sk' => 'Popis', | ||
'description:cs' => 'Popis', | ||
]; | ||
|
||
protected array $surfaces = [ | ||
'J' => 'jiný', | ||
'L' => 'lesklý', | ||
'M' => 'matný', | ||
'P' => 'polomatný', | ||
'R' => 'rastr', | ||
'V' => 'velvet', | ||
]; | ||
|
||
protected array $zooms = [ | ||
'K' => 'kontaktná kópia', | ||
'M' => 'zmenšovanie', | ||
'V' => 'zväčšovanie', | ||
]; | ||
|
||
protected array $stateEditions = [ | ||
'K' => 'kópia', | ||
'N' => 'neznámy', | ||
'O' => 'originál', | ||
'P' => 'reprodukcia', | ||
]; | ||
|
||
protected function hydrateTitle(array $record, string $locale): ?string | ||
{ | ||
if ($record['Název'] !== null) { | ||
return in_array($locale, ['sk', 'cs']) ? $record['Název'] : null; | ||
} elseif ($record['Předmět'] !== null) { | ||
return in_array($locale, ['sk', 'cs']) ? $record['Předmět'] : null; | ||
} else { | ||
return $this->translator->get('item.untitled', locale: $locale); | ||
} | ||
} | ||
|
||
protected function hydrateStateEdition(array $record, string $locale): ?string | ||
{ | ||
if ($record['Původnost'] === null) { | ||
return null; | ||
} | ||
|
||
$key = $this->stateEditions[$record['Původnost']]; | ||
return trans("item.state_editions.$key", locale: $locale); | ||
} | ||
|
||
protected function hydrateMedium(array $record, string $locale): ?string | ||
{ | ||
$media = collect(); | ||
|
||
$medium = $record['Materiál']; | ||
if ($record['Povrch'] !== null) { | ||
$medium .= Item::TREE_DELIMITER . $this->surfaces[$record['Povrch']]; | ||
} | ||
if ($medium) { | ||
$media[] = $medium; | ||
} | ||
|
||
$colorMedia = [ | ||
'CP' => 'papír/pastelový papír', | ||
]; | ||
if ($record['Barva'] !== null && Arr::has($colorMedia, $record['Barva'])) { | ||
$media[] = Arr::get($colorMedia, $record['Barva']); | ||
} | ||
|
||
return $media | ||
->map(function (string $medium) use ($locale) { | ||
if ($locale === 'cs') { | ||
return $medium; | ||
} | ||
|
||
$key = $this->mediumTranslationKeys[$medium] ?? null; | ||
return $key ? trans("item.media.$key", locale: $locale) : null; | ||
}) | ||
->filter() | ||
->join('; '); | ||
} | ||
|
||
protected function hydrateTechnique(array $record, string $locale): ?string | ||
{ | ||
$techniqueTranslationKeys = collect(); | ||
if ($record['Zoom'] !== null) { | ||
$techniqueTranslationKeys[] = $this->zooms[$record['Zoom']]; | ||
} | ||
|
||
$colors = [ | ||
'B' => ['farebná fotografia'], | ||
'C' => ['čiernobiela fotografia'], | ||
'CK' => ['kolorovanie'], | ||
'CT' => ['tónovanie'], | ||
'CTK' => ['tónovanie', 'kolorovanie'], | ||
'J' => ['iná technika'], | ||
]; | ||
$colorTranslationKeys = $colors[$record['Barva']] ?? null; | ||
if ($colorTranslationKeys) { | ||
foreach ($colorTranslationKeys as $colorTranslationKey) { | ||
$techniqueTranslationKeys[] = $colorTranslationKey; | ||
} | ||
} | ||
|
||
return $techniqueTranslationKeys | ||
->map(fn(string $key) => trans("item.techniques.$key", locale: $locale)) | ||
->join('; ') ?: | ||
null; | ||
} | ||
|
||
protected function hydrateWorkType(array $record, string $locale): ?string | ||
{ | ||
$workType = 'fotografie'; | ||
if ($record['Předmět'] !== null) { | ||
$workType .= Item::TREE_DELIMITER . $record['Předmět']; | ||
} | ||
|
||
if ($locale === 'cs') { | ||
return $workType; | ||
} | ||
|
||
$key = $this->workTypeTranslationKeys[$workType] ?? null; | ||
return $key ? trans("item.work_types.$key", locale: $locale) : null; | ||
} | ||
|
||
protected function hydrateRelationshipType(array $record, string $locale): ?string | ||
{ | ||
if ($record['Okolnosti'] === 'Archiv negativů Dagmar Hochové') { | ||
return trans('importer.mg.relationship_type.from_set', locale: $locale); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected function hydrateRelatedWork(array $record, string $locale): ?string | ||
{ | ||
if ($record['Okolnosti'] === 'Archiv negativů Dagmar Hochové') { | ||
return trans('importer.mg.related_work.dagmar_hochova', locale: $locale); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace App\Importers; | ||
|
||
trait MgImporterTrait | ||
{ | ||
protected array $mediumTranslationKeys; | ||
protected array $techniqueTranslationKeys; | ||
protected array $workTypeTranslationKeys; | ||
protected array $topicTranslationKeys; | ||
|
||
protected function init(): void | ||
{ | ||
$this->filters[] = function (array $record) { | ||
return $record['Plus2T'] != 'ODPIS'; | ||
}; | ||
|
||
$this->sanitizers[] = function ($value) { | ||
return empty_to_null($value); | ||
}; | ||
|
||
$this->mediumTranslationKeys = array_flip(trans('item.media', locale: 'cs')); | ||
$this->techniqueTranslationKeys = array_flip(trans('item.techniques', locale: 'cs')); | ||
$this->workTypeTranslationKeys = array_flip(trans('item.work_types', locale: 'cs')); | ||
$this->topicTranslationKeys = array_flip(trans('item.topics', locale: 'cs')); | ||
} | ||
|
||
protected function getItemId(array $record): string | ||
{ | ||
$id = sprintf('CZE:MG.%s_%s', $record['Rada_S'], (int) $record['PorC_S']); | ||
if ($record['Lomeni_S'] != '_') { | ||
$id = sprintf('%s-%s', $id, $record['Lomeni_S']); | ||
} | ||
|
||
return $id; | ||
} | ||
|
||
protected function getItemImageFilenameFormat(array $record): string | ||
{ | ||
$filename = sprintf( | ||
'%s%s', | ||
$record['Rada_S'], | ||
str_pad($record['PorC_S'], 6, '0', STR_PAD_LEFT) | ||
); | ||
if ($record['Lomeni_S'] != '_') { | ||
$filename = sprintf('%s-%s', $filename, $record['Lomeni_S']); | ||
} | ||
|
||
return sprintf('%s(_.*)?', preg_quote($filename)); | ||
} | ||
|
||
protected function hydrateIdentifier(array $record): string | ||
{ | ||
$identifier = sprintf('%s %s', $record['Rada_S'], (int) $record['PorC_S']); | ||
if ($record['Lomeni_S'] != '_') { | ||
$identifier = sprintf('%s/%s', $identifier, $record['Lomeni_S']); | ||
} | ||
|
||
return $identifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.