Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/RecordManager/Finna/Record/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public function toSolrArray(?Database $db = null)
$data['subtitle_lng_str_mv']
= $this->metadataUtils->normalizeLanguageStrings($subtitles);

$data['color_str_mv'] = $this->getColors();

return $data;
}

Expand Down Expand Up @@ -284,6 +286,16 @@ public function getSubtitleLanguages()
return $result;
}

/**
* Return colors.
*
* @return array
*/
protected function getColors(): array
{
return $this->getProductionEventAttribute('elokuva-alkupvari');
}

/**
* Get all authors or authors by relator codes.
*
Expand Down
76 changes: 58 additions & 18 deletions src/RecordManager/Finna/Record/Lido.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ class Lido extends \RecordManager\Base\Record\Lido
'kiinteistörekisteri' => 'kiinteistötunnus',
];

/**
* Classification types which should be excluded from classifications.
*
* @var array
*/
protected $excludedClassifications = ['language', 'colour content', 'color content'];

/**
* Materials/techniques types which should be included in colors
*
* @var array
*/
protected $colorTypes = [
'colour name', 'color name', 'väri',
'http://terminology.lido-schema.org/lido00479',
];

/**
* Hierarchy fields included in allfields.
*
Expand Down Expand Up @@ -256,6 +273,7 @@ public function toSolrArray(?Database $db = null)
// Keep classification_str_mv for backward-compatibility for now
$data['classification_txt_mv'] = $data['classification_str_mv']
= $this->getClassifications();
$data['color_str_mv'] = $this->getColors();
$data['exhibition_str_mv'] = $this->getEventNames('näyttely');

$data['category_str_mv'] = $this->getCategories();
Expand Down Expand Up @@ -1930,21 +1948,56 @@ protected function parseLidoDateRange($input)
/**
* Return the classifications.
*
* @param array $include Classification types to include.
*
* @link http://www.lido-schema.org/schema/v1.0/lido-v1.0-schema-listing.html
* #objectClassificationWrap
* @return array
*/
protected function getClassifications()
protected function getClassifications(array $include = []): array
{
$results = [];
foreach (
$this->doc->lido->descriptiveMetadata->objectClassificationWrap
->classificationWrap->classification ?? [] as $classification
) {
$type = trim((string)$classification->attributes()->type);
if ('language' !== $type && !empty($classification->term)) {
$type = mb_strtolower(trim((string)($classification->attributes()->type ?? '')), 'UTF-8');
$accepted = $include ? in_array($type, $include) : !in_array($type, $this->excludedClassifications);
if ($accepted) {
foreach ($classification->term as $term) {
$results[] = (string)$term;
if ($trimmed = trim((string)$term)) {
$results[] = $trimmed;
}
}
}
}
return $results;
}

/**
* Return colors.
*
* @return array
*/
protected function getColors(): array
{
// For backward compatibility: Include color content classifications
$results = $this->getClassifications(['colour content', 'color content']);
foreach (
$this->doc->lido->descriptiveMetadata->objectIdentificationWrap->objectMaterialsTechWrap
->objectMaterialsTechSet ?? [] as $set
) {
foreach ($set->materialsTech as $materialsTech) {
foreach ($materialsTech->termMaterialsTech as $termMaterialsTech) {
$type = mb_strtolower(trim((string)($termMaterialsTech->attributes()->type ?? '')), 'UTF-8');
if (!in_array($type, $this->colorTypes)) {
continue;
}
foreach ($termMaterialsTech->term as $term) {
if ($trimmed = trim((string)$term)) {
$results[] = $trimmed;
}
}
}
}
}
Expand Down Expand Up @@ -2341,20 +2394,7 @@ protected function isFreeOnline(): bool
*/
protected function getLanguages(): array
{
$classifications = $this->doc->lido->descriptiveMetadata
->objectClassificationWrap->classificationWrap->classification ?? [];
$result = [];
foreach ($classifications as $classification) {
$type = trim((string)$classification->attributes()->type);
if ('language' === $type) {
foreach ($classification->term as $lang) {
if ($trimmed = trim((string)$lang)) {
$result[] = $trimmed;
}
}
}
}
return array_unique($result);
return array_unique($this->getClassifications(['language']));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/RecordManagerTest/Finna/Record/ForwardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,9 @@ public function testForward1()
2 => 'Asuintalot, omakotitalot, villat ja kartanot',
3 => 'Maatilat, pientilat, mökit, torpat, maatalousrakennukset ja aitat',
],
'color_str_mv' => [
'väri',
],
];

$this->compareArray($expected, $fields, 'toSolrArray');
Expand Down
10 changes: 10 additions & 0 deletions tests/RecordManagerTest/Finna/Record/LidoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public function testMusketti2()
'fi',
'sv',
'en',
'mustavalkoinen',
'Imatrankoski',
'Imatra fors',
'33,1.',
Expand All @@ -240,6 +241,9 @@ public function testMusketti2()
'Kalasatama',
'Capellanranta 1 ja 3 välillä',
'Helsinki',
'keltainen',
'yellow',
'punainen',
'valmistus',
'http://urn.fi/URN:NBN:fi:au:finaf:000173713',
'https://isni.org/isni/0000000073500621',
Expand Down Expand Up @@ -290,6 +294,12 @@ public function testMusketti2()
'classification_txt_mv' => [
'valokuva',
],
'color_str_mv' => [
'mustavalkoinen',
'keltainen',
'yellow',
'punainen',
],
'exhibition_str_mv' => [],
'main_date_str' => '1897',
'main_date' => '1897-01-01T00:00:00Z',
Expand Down
16 changes: 16 additions & 0 deletions tests/fixtures/Finna/record/musketti2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<classification type="language">
<term>en</term>
</classification>
<classification type="colour content">
<term>mustavalkoinen</term>
</classification>
</classificationWrap>
</objectClassificationWrap>
<objectIdentificationWrap>
Expand Down Expand Up @@ -113,6 +116,19 @@
<objectMeasurements />
</objectMeasurementsSet>
</objectMeasurementsWrap>
<objectMaterialsTechWrap>
<objectMaterialsTechSet>
<materialsTech>
<termMaterialsTech type="väri">
<term lang="fi">keltainen</term>
<term lang="en">yellow</term>
</termMaterialsTech>
<termMaterialsTech type="Colour name">
<term>punainen</term>
</termMaterialsTech>
</materialsTech>
</objectMaterialsTechSet>
</objectMaterialsTechWrap>
</objectIdentificationWrap>
<eventWrap>
<eventSet>
Expand Down
Loading