Skip to content

Commit

Permalink
[import] mg foto importer
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Dec 7, 2023
1 parent a90b452 commit b475e16
Show file tree
Hide file tree
Showing 10 changed files with 631 additions and 88 deletions.
93 changes: 93 additions & 0 deletions app/Importers/AbstractMgImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Importers;

class AbstractMgImporter extends AbstractImporter
{
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 array $workTypes = [
'Ar' => 'architektura',
'Bi' => 'bibliofilie a staré tisky',
'' => 'dřevo, nábytek a design',
'Fo' => 'fotografie',
'Gr' => 'grafika',
'Gu' => 'grafický design',
'Ji' => 'jiné',
'Ke' => 'keramika',
'Ko' => 'kovy',
'Kr' => 'kresba',
'Ob' => 'obrazy',
'Sk' => 'sklo',
'So' => 'sochy',
'Šp' => 'šperky',
'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;
}
}
138 changes: 138 additions & 0 deletions app/Importers/MgFotoImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

namespace App\Importers;

use App\Item;

class MgFotoImporter extends AbstractMgImporter
{
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' => 'kontakt fotografie',
'M' => 'zmenšenina fotografie',
'V' => 'zväčšenina fotografie',
];

protected array $colors = [
'B' => 'farebná fotografia',
'C' => 'čiernobiela fotografia',
'CK' => 'kolorováno fotografie',
'CP' => 'pastelový papier fotografia',
'CT' => 'tónovaná fotografia',
'CTK' => 'tónovaná, kolorovaná fotografia',
'J' => 'iná fotografia',
];

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
{
$medium = $record['Materiál'];
if ($record['Povrch'] !== null) {
$medium .= Item::TREE_DELIMITER . $this->surfaces[$record['Povrch']];
}

if ($locale === 'cs') {
return $medium;
}

$key = $this->mediumTranslationKeys[$medium] ?? null;
return $key ? trans("item.media.$key", locale: $locale) : null;
}

protected function hydrateTechnique(array $record, string $locale): ?string
{
$techniques = collect();
if ($record['Zoom'] !== null) {
$key = $this->zooms[$record['Zoom']];
$techniques[] = trans("item.techniques.$key", locale: $locale);
}

if ($record['Barva'] !== null) {
$key = $this->colors[$record['Barva']];
$techniques[] = trans("item.techniques.$key", locale: $locale);
}

return $techniques->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;
}
}
89 changes: 1 addition & 88 deletions app/Importers/MgImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@

use App\Item;

class MgImporter extends AbstractImporter
class MgImporter extends AbstractMgImporter
{
protected static $options = [
'delimiter' => ';',
'enclosure' => '"',
'escape' => '\\',
'newline' => "\r\n",
'input_encoding' => 'CP1250',
];

protected $mapping = [
'date_earliest' => 'RokOd',
'date_latest' => 'Do',
Expand All @@ -29,85 +21,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',
'' => 'dřevo, nábytek a design',
'Fo' => 'fotografie',
'Gr' => 'grafika',
'Gu' => 'grafický design',
'Ji' => 'jiné',
'Ke' => 'keramika',
'Ko' => 'kovy',
'Kr' => 'kresba',
'Ob' => 'obrazy',
'Sk' => 'sklo',
'So' => 'sochy',
'Šp' => 'šperky',
'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
10 changes: 10 additions & 0 deletions lang/cs/importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
'related_work' => [
'biennal_brno' => 'Bienále Brno',
'jv' => 'Archiv a sbírka Jiřího Valocha',
'dagmar_hochova' => 'Archiv negativů Dagmar Hochové',
],
'state_edition' => [
'AP' => 'autorizovaný pozitiv',
'F' => 'facsimile',
'J' => 'jiné',
'K' => 'kopie',
'NAP' => 'neautorský pozitiv',
'O' => 'originál',
'RT' => 'reprodukce tisková',
],
],
];
16 changes: 16 additions & 0 deletions lang/cs/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,24 @@
'techniques' => [
'akvarel' => 'akvarel',
'akvarel/čierny' => 'akvarel/černý',
'farebná fotografia' => 'barvená fotografie',
'iná fotografia' => 'jiná fotografie',
'kolorovaná fotografia' => 'kolorovaná fotografie',
'kontakt fotografie' => 'kontakt fotografie',
'pastelový papier fotografia' => 'pastelový papír fotografie',
'tónovaná fotografia' => 'tónovaná fotografie',
'tónovaná, kolorovaná fotografia' => 'tónovaná, kolorovaná fotografie',
'zmenšenina fotografie' => 'zmenšenina fotografie',
'zväčšenina fotografie' => 'zvětšenina fotografie',
'č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',
],
];
10 changes: 10 additions & 0 deletions lang/en/importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@
'related_work' => [
'biennal_brno' => 'Biennal Brno',
'jv' => 'Archive and collection of Jiří Valoch',
'dagmar_hochova' => 'Archive of negatives of Dagmar Hochová',
],
'state_edition' => [
'AP' => 'authorized positive',
'F' => 'facsimile',
'J' => 'other',
'K' => 'copy',
'NAP' => 'non-authorized positive',
'O' => 'original',
'RT' => 'reproduction print',
],
],
];
Loading

0 comments on commit b475e16

Please sign in to comment.