Skip to content

Commit

Permalink
Merge pull request #929 from SlovakNationalGallery/MG-13
Browse files Browse the repository at this point in the history
[import] mg foto importer
  • Loading branch information
rastislav-chynoransky authored Dec 20, 2023
2 parents f7939f7 + 10760b1 commit 8db57cb
Show file tree
Hide file tree
Showing 10 changed files with 635 additions and 61 deletions.
174 changes: 174 additions & 0 deletions app/Importers/MgFotoImporter.php
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;
}
}
69 changes: 8 additions & 61 deletions app/Importers/MgImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class MgImporter extends AbstractImporter
{
use MgImporterTrait;

protected static $options = [
'delimiter' => ';',
'enclosure' => '"',
Expand All @@ -14,6 +16,12 @@ class MgImporter extends AbstractImporter
'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' => 'RokOd',
'date_latest' => 'Do',
Expand All @@ -29,12 +37,6 @@ class MgImporter extends AbstractImporter
'state_edition:cs' => 'Původnost',
];

protected $defaults = [
'author' => 'neurčený autor', // todo translatable author
'gallery:sk' => 'Moravská galerie, MG',
'gallery:cs' => 'Moravská galerie, MG',
];

protected array $workTypes = [
'Ar' => 'architektura',
'Bi' => 'bibliofilie a staré tisky',
Expand All @@ -53,61 +55,6 @@ class MgImporter extends AbstractImporter
'Te' => 'textil',
];

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;
}

protected function hydrateTitle(array $record, string $locale): ?string
{
if ($record['Titul'] !== null) {
Expand Down
61 changes: 61 additions & 0 deletions app/Importers/MgImporterTrait.php
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;
}
}
1 change: 1 addition & 0 deletions lang/cs/importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'related_work' => [
'biennal_brno' => 'Bienále Brno',
'jv' => 'Archiv a sbírka Jiřího Valocha',
'dagmar_hochova' => 'Archiv negativů Dagmar Hochové',
],
],
];
15 changes: 15 additions & 0 deletions lang/cs/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,27 @@
'media' => [
'papier' => 'papír',
'papier/matný' => 'papír/matný',
'papier/pastelový papier' => 'papír/pastelový papír',
],
'techniques' => [
'akvarel' => 'akvarel',
'akvarel/čierny' => 'akvarel/černý',
'farebná fotografia' => 'barvená fotografie',
'iná technika' => 'jiná technika',
'kolorovanie' => 'kolorování',
'kontaktná kópia' => 'kontaktní kópie',
'tónovanie' => 'tónování',
'zmenšovanie' => 'zmenšování',
'zväčšovanie' => 'zvětšování',
'čiernobiela fotografia' => 'černobílá fotografie',
],
'topics' => [
'figurálna kompozícia' => 'figurální kompozice',
],
'state_editions' => [
'kópia' => 'kopie',
'neznámy' => 'neznámý',
'originál' => 'originál',
'reprodukcia' => 'reprodukce',
],
];
1 change: 1 addition & 0 deletions lang/en/importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
'related_work' => [
'biennal_brno' => 'Biennal Brno',
'jv' => 'Archive and collection of Jiří Valoch',
'dagmar_hochova' => 'Archive of negatives of Dagmar Hochová',
],
],
];
Loading

0 comments on commit 8db57cb

Please sign in to comment.