Skip to content

Commit

Permalink
[FINNA-2789] Refactor EAD3 splitter for easier extensibility (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
siiriylonen authored Nov 28, 2024
1 parent e91835f commit 02c7fca
Showing 1 changed file with 56 additions and 43 deletions.
99 changes: 56 additions & 43 deletions src/RecordManager/Base/Splitter/Ead3.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,62 @@ public function getNextRecord()
$this->appendXMLFiltered($record, $child);
}

$ancestorDid = $original->xpath('ancestor::*/did');

if ($ancestorDid) {
// Append any ancestor did's
foreach (array_reverse($ancestorDid) as $did) {
$this->appendXML($record, $did, $this->nonInheritedFields);
}
}

if ($record->getName() !== 'archdesc') {
foreach ($this->doc->archdesc->bibliography ?? [] as $elem) {
$this->appendXML($record, $elem, $this->nonInheritedFields);
}

foreach ($this->doc->archdesc->accessrestrict ?? [] as $elem) {
$this->appendXML($record, $elem, $this->nonInheritedFields);
}
}

$this->addAdditionalData($record, $original);

return ['metadata' => $record->asXML()];
}

/**
* Get archive title
*
* @return string
*/
protected function getArchiveTitle(): string
{
return (string)$this->doc->archdesc->did->unittitle;
}

/**
* Get parent unit id for prepending to parent title
*
* @param \SimpleXMLElement $parentDid Parent did
*
* @return string
*/
protected function getParentUnitId(\SimpleXMLElement $parentDid): string
{
return (string)($parentDid->unitid ?? '');
}

/**
* Add and form additional data to record
*
* @param \SimpleXMLElement $record The record
* @param \SimpleXMLElement $original The original record
*
* @return void
*/
protected function addAdditionalData(&$record, &$original): void
{
$addData = $record->addChild('add-data');
$unitId = '';

Expand Down Expand Up @@ -205,25 +261,6 @@ public function getNextRecord()
$absolute->addAttribute('subtitle', $this->archiveSubTitle);
}

$ancestorDid = $original->xpath('ancestor::*/did');

if ($ancestorDid) {
// Append any ancestor did's
foreach (array_reverse($ancestorDid) as $did) {
$this->appendXML($record, $did, $this->nonInheritedFields);
}
}

if ($record->getName() !== 'archdesc') {
foreach ($this->doc->archdesc->bibliography ?? [] as $elem) {
$this->appendXML($record, $elem, $this->nonInheritedFields);
}

foreach ($this->doc->archdesc->accessrestrict ?? [] as $elem) {
$this->appendXML($record, $elem, $this->nonInheritedFields);
}
}

$parentDid = $original->xpath('parent::*/did');
if ($parentDid) {
$parentDid = $parentDid[0];
Expand Down Expand Up @@ -298,29 +335,5 @@ public function getNextRecord()
$parent->addAttribute('level', 'archive');
}
}

return ['metadata' => $record->asXML()];
}

/**
* Get archive title
*
* @return string
*/
protected function getArchiveTitle(): string
{
return (string)$this->doc->archdesc->did->unittitle;
}

/**
* Get parent unit id for prepending to parent title
*
* @param \SimpleXMLElement $parentDid Parent did
*
* @return string
*/
protected function getParentUnitId(\SimpleXMLElement $parentDid): string
{
return (string)($parentDid->unitid ?? '');
}
}

0 comments on commit 02c7fca

Please sign in to comment.