Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMP importer #1045

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/Filesystem/WebDAVAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Filesystem;

use League\Flysystem\FileAttributes;
use League\Flysystem\WebDAV\WebDAVAdapter as BaseWebDAVAdapter;

/**
* This class is a workaround for the issue of handling spaces in paths
*/
class WebDAVAdapter extends BaseWebDAVAdapter
{
public function lastModified(string $path): FileAttributes
{
$path = $this->encodePath($path);
return parent::lastModified($path);
}
}
2 changes: 1 addition & 1 deletion app/Importers/AbstractImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected function getJp2Files(
return $this->iipFilesMap[$import_record]
->filter(
fn(SplFileInfo $file) => preg_match(
sprintf('#^%s\.jp2$#', $image_filename_format),
sprintf('#^%s\.jp[2f]$#', $image_filename_format),
$file->getBasename()
)
)
Expand Down
150 changes: 150 additions & 0 deletions app/Importers/MmpImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

namespace App\Importers;

use Illuminate\Support\Facades\Date;

class MmpImporter extends AbstractImporter
{
protected $mapping = [
'identifier' => 'Inventární číslo',
'title' => 'Titul',
'dating' => 'Datace vzniku',
'inscription' => 'Signatura',
];

protected $defaults = [
'gallery:sk' => 'Múzeum Prahy, MMP',
'gallery:cs' => 'Muzeum Prahy, MMP',
];

private array $workTypeTranslationKeys;
private array $techniqueTranslationKeys;
private array $mediumTranslationKeys;
private array $topicTranslationKeys;

protected function init(): void
{
$this->sanitizers[] = function ($value) {
return empty_to_null(trim($value));
};

$this->workTypeTranslationKeys = array_flip(trans('item.work_types', locale: 'cs'));
$this->techniqueTranslationKeys = array_flip(trans('item.techniques', locale: 'cs'));
$this->mediumTranslationKeys = array_flip(trans('item.media', locale: 'cs'));
$this->topicTranslationKeys = array_flip(trans('item.topics', locale: 'cs'));
}

protected function getItemId(array $record): string
{
return str($record['Inventární číslo'])
->swap([
' ' => '_',
'/' => '-',
])
->prepend('CZE:MP.');
}

protected function getItemImageFilenameFormat(array $record): string
{
return str($record['Inventární číslo'])
->replace('/', '_')
->append('(-.*)?');
}

protected function hydrateAuthor(array $record): string
{
if ($record['Autor'] === 'Anonym') {
return 'Neznámy autor';
}

return str($record['Autor'])
->trim()
->replaceMatches('/(.*?) /', '$1, ', 1);
}

protected function hydrateWorkType(array $record, string $locale): ?string
{
$replacements = [
'malba' => 'malířství',
];

return str($record['Výtvarný druh'])
->split('/\s*;\s*/')
->map(fn (string $workType) => $replacements[$workType] ?? $workType)
->when($locale !== 'cs', fn ($workTypes) => $workTypes->map(function (string $workType) use ($locale) {
$key = $this->workTypeTranslationKeys[$workType] ?? null;
return $key ? trans("item.work_types.$key", locale: $locale) : null;
}))
->filter()
->join('; ') ?: null;
}

protected function hydrateTechnique(array $record, string $locale): ?string
{
if ($locale === 'cs') {
return $record['Technika'];
}

return str($record['Technika'])
->split('/\s*;\s*/')
->map(function (string $technique) use ($locale) {
$key = $this->techniqueTranslationKeys[$technique] ?? null;
return $key ? trans("item.techniques.$key", locale: $locale) : null;
})
->filter()
->join('; ') ?: null;
}

protected function hydrateMedium(array $record, string $locale): ?string
{
if ($locale === 'cs') {
return $record['Materiál'];
}

return str($record['Materiál'])
->split('/\s*;\s*/')
->map(function (string $medium) use ($locale) {
$key = $this->mediumTranslationKeys[$medium] ?? null;
return $key ? trans("item.media.$key", locale: $locale) : null;
})
->filter()
->join('; ') ?: null;
}

protected function hydrateTopic(array $record, string $locale): ?string
{
if ($locale === 'cs') {
return $record['Námět/téma'];
}

return str($record['Námět/téma'])
->split('/\s*;\s*/')
->map(function (string $topic) use ($locale) {
$key = $this->topicTranslationKeys[$topic] ?? null;
return $key ? trans("item.topics.$key", locale: $locale) : null;
})
->filter()
->join('; ') ?: null;
}

protected function hydrateMeasurement(array $record, $locale): ?string
{
if (empty($record['Rozměr'])) {
return null;
}

$replacements = trans('item.measurement_replacements', [], $locale);
return strtr($record['Rozměr'], $replacements);
}

protected function hydrateDateEarliest(array $record): int
{
return Date::createFromFormat('d.m.Y', $record['(n) Datace OD'])->year;
}

protected function hydrateDateLatest(array $record): int
{
return Date::createFromFormat('d.m.Y', $record['(n) Datace DO'])->year;
}
}
2 changes: 1 addition & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace App\Providers;

use App\Filesystem\WebDAVAdapter;
use App\Elasticsearch\Repositories\AuthorityRepository;
use App\Elasticsearch\Repositories\ItemRepository;
use App\Enums\FrontendEnum;
Expand All @@ -15,7 +16,6 @@
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use League\Flysystem\WebDAV\WebDAVAdapter;
use Sabre\DAV\Client;

class AppServiceProvider extends ServiceProvider
Expand Down
63 changes: 33 additions & 30 deletions lang/cs/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,36 +108,39 @@
],
],
'measurement_replacements' => [
'a' => 'výška hlavní části',
'a.' => 'výška hlavní části',
'b' => 'výška vedlejší části',
'b.' => 'výška vedlejší části',
'čas' => 'čas',
'd' => 'délka',
'd.' => 'délka',
'h' => 'hloubka/tloušťka',
'h.' => 'hloubka/tloušťka',
'hmot' => 'hmotnost',
'hmot.' => 'hmotnost',
'hr' => 'hloubka s rámem',
'jiný' => 'jiný nespecifikovaný',
'p' => 'průměr/ráže',
'p.' => 'průměr/ráže',
'r.' => 'ráže',
'ryz' => 'ryzost',
's' => 'šířka',
's.' => 'šířka',
'sd.' => 'šířka grafické desky',
'sp' => 'šířka s paspartou',
'sp.' => 'šířka s paspartou',
'sr' => 'šířka s rámem',
'v' => 'celková výška/délka',
'v.' => 'celková výška/délka',
'vd.' => 'výška grafické desky',
'vp' => 'výška s paspartou',
'vp.' => 'výška s paspartou',
'vr' => 'výška s rámem',
'=' => ' ',
'a=' => 'výška hlavní části ',
'a.=' => 'výška hlavní části ',
'b=' => 'výška vedlejší části ',
'b.=' => 'výška vedlejší části ',
'čas=' => 'čas ',
'd=' => 'délka ',
'd.=' => 'délka ',
'h=' => 'hloubka/tloušťka ',
'h.=' => 'hloubka/tloušťka ',
'hmot=' => 'hmotnost ',
'hmot.=' => 'hmotnost ',
'hr=' => 'hloubka s rámem ',
'jiný=' => 'jiný nespecifikovaný ',
'p=' => 'průměr/ráže ',
'p.=' => 'průměr/ráže ',
'r.=' => 'ráže ',
'ryz=' => 'ryzost ',
's=' => 'šířka ',
's.=' => 'šířka ',
'sd.=' => 'šířka grafické desky ',
'sp=' => 'šířka s paspartou ',
'sp.=' => 'šířka s paspartou ',
'sr=' => 'šířka s rámem ',
'v=' => 'celková výška/délka ',
'v.=' => 'celková výška/délka ',
'vd.=' => 'výška grafické desky ',
'vp=' => 'výška s paspartou ',
'vp.=' => 'výška s paspartou ',
'vr=' => 'výška s rámem ',
'rv.=' => 'výška s rámem ',
'rš.=' => 'šířka s rámem ',
'v-cm=' => 'výška ',
'š-cm=' => 'šířka ',
],
'untitled' => 'bez názvu',
'authority_roles' => [
Expand Down
63 changes: 33 additions & 30 deletions lang/en/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,39 @@
],
],
'measurement_replacements' => [
'a' => 'height of the main part',
'a.' => 'height of the main part',
'b' => 'height of the secondary part',
'b.' => 'height of the secondary part',
'čas' => 'time',
'd' => 'length',
'd.' => 'length',
'h' => 'depth/thickness',
'h.' => 'depth/thickness',
'hmot' => 'mass',
'hmot.' => 'mass',
'hr' => 'depth with frame',
'jiný' => 'other, unspecified',
'p' => 'diameter, calibre/gauge',
'p.' => 'diameter, calibre/gauge',
'r.' => 'calibre/gauge',
'ryz' => 'purity',
's' => 'width',
's.' => 'width',
'sd.' => 'width of the printing plate',
'sp' => 'width with mount',
'sp.' => 'width with mount',
'sr' => 'width with frame',
'v' => 'overall height/length',
'v.' => 'overall height/length',
'vd.' => 'height of the printing plate',
'vp' => 'height with mount',
'vp.' => 'height with mount',
'vr' => 'height with frame',
'=' => ' ',
'a=' => 'height of the main part ',
'a.=' => 'height of the main part ',
'b=' => 'height of the secondary part ',
'b.=' => 'height of the secondary part ',
'čas=' => 'time ',
'd=' => 'length ',
'd.=' => 'length ',
'h=' => 'depth/thickness ',
'h.=' => 'depth/thickness ',
'hmot=' => 'mass ',
'hmot.=' => 'mass ',
'hr=' => 'depth with frame ',
'jiný=' => 'other, unspecified ',
'p=' => 'diameter, calibre/gauge ',
'p.=' => 'diameter, calibre/gauge ',
'r.=' => 'calibre/gauge ',
'ryz=' => 'purity ',
's=' => 'width ',
's.=' => 'width ',
'sd.=' => 'width of the printing plate ',
'sp=' => 'width with mount ',
'sp.=' => 'width with mount ',
'sr=' => 'width with frame ',
'v=' => 'overall height/length ',
'v.=' => 'overall height/length ',
'vd.=' => 'height of the printing plate ',
'vp=' => 'height with mount ',
'vp.=' => 'height with mount ',
'vr=' => 'height with frame ',
'rv.=' => 'height with frame ',
'rš.=' => 'width with frame ',
'v-cm=' => 'height ',
'š-cm=' => 'width ',
],
'untitled' => 'untitled',
'authority_roles' => [
Expand Down
Loading