diff --git a/src/RecordManager/Finna/Record/Aipa.php b/src/RecordManager/Finna/Record/Aipa.php index 2c787ca4..b724ddf2 100644 --- a/src/RecordManager/Finna/Record/Aipa.php +++ b/src/RecordManager/Finna/Record/Aipa.php @@ -47,6 +47,7 @@ */ class Aipa extends Qdc { + use AuthoritySupportTrait; use CreateRecordTrait; /** @@ -116,6 +117,7 @@ public function toSolrArray(?Database $db = null) $data['record_format'] = 'aipa'; $data['educational_material_type_str_mv'] = $this->getFormat(); + $data['topic_id_str_mv'] = $this->getTopicIDs(); // Merge fields from encapsulated records. foreach ($this->doc->item as $item) { @@ -154,6 +156,32 @@ public function getFormat() return (string)($this->doc->type); } + /** + * Get all topic identifiers (for enrichment) + * + * @return array + */ + public function getRawTopicIds(): array + { + $results = []; + foreach ($this->doc->subject ?? [] as $subject) { + if ($id = trim((string)($subject->attributes()->identifier))) { + $results[] = $id; + } + } + return array_unique($results); + } + + /** + * Return subject identifiers associated with object. + * + * @return array + */ + protected function getTopicIDs(): array + { + return $this->addNamespaceToAuthorityIds($this->getRawTopicIDs(), 'topic'); + } + /** * Return URLs associated with object *