-
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.
- Loading branch information
1 parent
a90b452
commit 61e2d1b
Showing
10 changed files
with
586 additions
and
70 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,75 @@ | ||
<?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 $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
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; | ||
} | ||
} |
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
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
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.