Skip to content

Commit

Permalink
Split getLogicalStructureInfo() function to satisfy Codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Jul 2, 2024
1 parent 704b450 commit 1d5aee9
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,27 +345,8 @@ protected function getLogicalStructureInfo(SimpleXMLElement $structure, bool $re
// Load physical structure.
$this->magicGetPhysicalStructure();
// Get the physical page or external file this structure element is pointing at.
// Is there a mptr node?
if (count($structure->children('http://www.loc.gov/METS/')->mptr)) {
// Yes. Get the file reference.
$details['points'] = (string) $structure->children('http://www.loc.gov/METS/')->mptr[0]->attributes('http://www.w3.org/1999/xlink')->href;
} elseif (
!empty($this->physicalStructure)
&& array_key_exists($details['id'], $this->smLinks['l2p'])
) {
// Link logical structure to the first corresponding physical page/track.
$details['points'] = max((int) array_search($this->smLinks['l2p'][$details['id']][0], $this->physicalStructure, true), 1);
$details['thumbnailId'] = $this->getThumbnail();
// Get page/track number of the first page/track related to this structure element.
$details['pagination'] = $this->physicalStructureInfo[$this->smLinks['l2p'][$details['id']][0]]['orderlabel'];
} elseif ($details['id'] == $this->magicGetToplevelId()) {
// Point to self if this is the toplevel structure.
$details['points'] = 1;
$details['thumbnailId'] = $this->getThumbnail();
}
if ($details['thumbnailId'] === null) {
unset($details['thumbnailId']);
}
$this->getPage($details, $structure->children('http://www.loc.gov/METS/')->mptr);

// Get the files this structure element is pointing at.
$fileUse = $this->magicGetFileGrps();
// Get the file representations from fileSec node.
Expand All @@ -391,6 +372,39 @@ protected function getLogicalStructureInfo(SimpleXMLElement $structure, bool $re
return $details;
}

/**
* Get the physical page or external file this structure element is pointing at.
*
* @access private
*
* @param array $details passed as reference
* @param array $metsPointers
*
* @return void
*/
private function getPage(array &$details, array $metsPointers) {
if (count($metsPointers)) {
// Yes. Get the file reference.
$details['points'] = (string) $metsPointers[0]->attributes('http://www.w3.org/1999/xlink')->href;
} elseif (
!empty($this->physicalStructure)
&& array_key_exists($details['id'], $this->smLinks['l2p'])
) {
// Link logical structure to the first corresponding physical page/track.
$details['points'] = max((int) array_search($this->smLinks['l2p'][$details['id']][0], $this->physicalStructure, true), 1);
$details['thumbnailId'] = $this->getThumbnail();
// Get page/track number of the first page/track related to this structure element.
$details['pagination'] = $this->physicalStructureInfo[$this->smLinks['l2p'][$details['id']][0]]['orderlabel'];
} elseif ($details['id'] == $this->magicGetToplevelId()) {
// Point to self if this is the toplevel structure.
$details['points'] = 1;
$details['thumbnailId'] = $this->getThumbnail();
}
if ($details['thumbnailId'] === null) {
unset($details['thumbnailId']);
}
}

/**
* Get thumbnail for logical structure info.
*
Expand Down

0 comments on commit 1d5aee9

Please sign in to comment.