-
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
9851bdd
commit a264ef7
Showing
5 changed files
with
162 additions
and
0 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
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,125 @@ | ||
<?php | ||
|
||
namespace App\Importers; | ||
|
||
use App\Enums\FrontendEnum; | ||
|
||
class UpmImporter extends AbstractImporter | ||
{ | ||
protected $mapping = [ | ||
'identifier' => 'Inventárníčíslo', | ||
'title:cs' => 'Název', | ||
'title:sk' => 'Název', | ||
'title:en' => 'Název EN', | ||
'author' => 'Autor', | ||
'dating:cs' => 'Datace', | ||
'dating:sk' => 'Datace', | ||
'date_earliest' => 'Od', | ||
'date_latest' => 'Do', | ||
'work_type:cs' => 'Výtvarný druh', | ||
'work_type:sk' => 'Výtvarný druh', | ||
'object_type:cs' => 'Typ', | ||
'object_type:sk' => 'Typ', | ||
'medium:cs' => 'Materiál', | ||
'medium:sk' => 'Materiál', | ||
'technique:cs' => 'Technika', | ||
'technique:sk' => 'Technika', | ||
'topic:cs' => 'Námět', | ||
'topic:sk' => 'Námět', | ||
'inscription:cs' => 'Značení', | ||
'inscription:sk' => 'Značení', | ||
'related_work:sk' => 'Sbírka', | ||
'related_work:cs' => 'Sbírka', | ||
'acquisition_date' => 'Datum akvizice', | ||
]; | ||
|
||
protected $defaults = [ | ||
'relationship_type:sk' => 'zo súboru', | ||
'relationship_type:cs' => 'ze souboru', | ||
'relationship_type:en' => 'collection', | ||
'author' => 'Neznámý autor', | ||
'gallery:cs' => 'Uměleckoprůmyslové museum v Praze, UPM', | ||
'gallery:sk' => 'Umeleckopriemyselné múzeum v Prahe, UPM', | ||
'frontends' => [ | ||
FrontendEnum::UPM, | ||
FrontendEnum::WEBUMENIA, | ||
], | ||
]; | ||
|
||
protected static $options = [ | ||
'delimiter' => ';', | ||
'enclosure' => '"', | ||
'escape' => '\\', | ||
'newline' => "\n", | ||
]; | ||
|
||
protected function init() | ||
{ | ||
$this->sanitizers[] = function ($value) { | ||
return empty_to_null(trim($value)); | ||
}; | ||
} | ||
|
||
protected function getItemId(array $record) | ||
{ | ||
return 'CZE:UPM.' . str($record['ID']) | ||
->explode('_') | ||
->transform(fn ($part) => str($part) | ||
->trim() | ||
->replaceMatches('/[^\w\d_]/', '-') | ||
) | ||
->join('_'); | ||
} | ||
|
||
protected function getItemImageFilenameFormat(array $record): string | ||
{ | ||
return str($record['ID']) | ||
->explode('_') | ||
->transform(fn ($part) => '0*' . preg_quote($part)) | ||
->join('_') . '(_.*)?'; | ||
} | ||
|
||
protected function hydratePlace(array $record, string $locale): ?string | ||
{ | ||
if (!in_array($locale, ['cs', 'sk'])) { | ||
return null; | ||
} | ||
|
||
$place = str($record['Vznik'])->match('/^([^;]+)/'); | ||
return $place->isNotEmpty() ? $place->toString() : null; | ||
} | ||
|
||
protected function hydrateAdditionals(array $record, string $locale): ?array | ||
{ | ||
if ($locale !== 'cs') { | ||
return null; | ||
} | ||
|
||
$additionals = []; | ||
|
||
if ($record['Způsob akvizice'] !== null) { | ||
$additionals['acquisition'] = $record['Způsob akvizice']; | ||
} | ||
|
||
if ($record['Výstava'] !== null) { | ||
$additionals['exhibiton'] = $record['Výstava']; | ||
} | ||
|
||
$producer = str($record['Vznik'])->match('/;(.+)/'); | ||
if ($producer->isNotEmpty()) { | ||
$additionals['producer'] = $producer->toString(); | ||
} | ||
|
||
return $additionals ?: null; | ||
} | ||
|
||
protected function hydrateMeasurement(array $record, $locale): ?string | ||
{ | ||
if (empty($record['Rozměry'])) { | ||
return null; | ||
} | ||
|
||
$replacements = trans('item.measurement_replacements', [], $locale); | ||
return strtr($record['Rozměry'], $replacements); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use App\Import; | ||
use App\Importers\UpmImporter; | ||
use Illuminate\Database\Seeder; | ||
|
||
class ImportsTableSeeder extends Seeder | ||
{ | ||
public function run() | ||
{ | ||
$imports = [ | ||
[ | ||
'name' => 'UPM', | ||
'dir_path' => 'UPM', | ||
'iip_dir_path' => 'UPM', | ||
'class_name' => UpmImporter::class, | ||
'disk' => 'import_iip', | ||
], | ||
]; | ||
|
||
foreach ($imports as $import) { | ||
Import::create($import); | ||
} | ||
} | ||
} |