Skip to content

Commit

Permalink
Ensure that it is a MetsDocument when calling the musical methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzor committed Jul 16, 2024
1 parent 1952af5 commit ff8c619
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
69 changes: 36 additions & 33 deletions Classes/Common/DocumentAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,57 +321,60 @@ protected function getMeasurePagesByFileId($fileId, $range = null)
{
// Get all measures referencing the fileid
$measures = [];
// Get the related page numbers
$measurePages = [];
$measureIndex = 1;
$startOrder = 0;
$endOrder = 0;

foreach ($this->document->getCurrentDocument()->musicalStructureInfo as $key => $musicalInfo) {
if ($musicalInfo['type'] === 'measure' && is_array($musicalInfo['files'])) {
foreach ($musicalInfo['files'] as $file) {
if ($file['fileid'] === $fileId && $file['type'] === 'IDREF') {
$measures[] = $musicalInfo;
if ($this->document->getCurrentDocument() instanceof MetsDocument) {
foreach ($this->document->getCurrentDocument()->musicalStructureInfo as $key => $musicalInfo) {
if ($musicalInfo['type'] === 'measure' && is_array($musicalInfo['files'])) {
foreach ($musicalInfo['files'] as $file) {
if ($file['fileid'] === $fileId && $file['type'] === 'IDREF') {
$measures[] = $musicalInfo;
}
}
}

if ($measureIndex === 1) {
$startOrder = $musicalInfo['order'];
}
if ($measureIndex === 1) {
$startOrder = $musicalInfo['order'];
}

$endOrder = $musicalInfo['order'];
$endOrder = $musicalInfo['order'];

$measureIndex += 1;
$measureIndex += 1;
}
}
}

// Filter measures by the given range of measure numbers
if ($measures && $range && !preg_match("/\ball\b/", $range)) {
$measureNumbers = [];
// Filter measures by the given range of measure numbers
if ($measures && $range && !preg_match("/\ball\b/", $range)) {
$measureNumbers = [];

$range = preg_replace("/\bend\b/", $endOrder, $range);
$range = preg_replace("/\bstart\b/", $startOrder, $range);
$range = preg_replace("/\bend\b/", $endOrder, $range);
$range = preg_replace("/\bstart\b/", $startOrder, $range);

$ranges = array_map('trim', explode(',', $range));
$ranges = array_map('trim', explode(',', $range));

foreach ($ranges as $measureNumber) {
if (preg_match('/\d+-\d+/', $measureNumber)) {
list($from,$to) = array_map('trim', explode('-', $measureNumber));
$measureNumbers = array_merge($measureNumbers, range($from, $to));
} else {
$measureNumbers[] = (int) $measureNumber;
foreach ($ranges as $measureNumber) {
if (preg_match('/\d+-\d+/', $measureNumber)) {
list($from, $to) = array_map('trim', explode('-', $measureNumber));
$measureNumbers = array_merge($measureNumbers, range($from, $to));
} else {
$measureNumbers[] = (int)$measureNumber;
}
}
}

foreach ($measures as $key => $measure) {
if (!in_array($measure['order'], $measureNumbers)) {
unset($measures[$key]);
foreach ($measures as $key => $measure) {
if (!in_array($measure['order'], $measureNumbers)) {
unset($measures[$key]);
}
}
}
}

// Get the related page numbers
$measurePages = [];
foreach ($measures as $measure) {
$measurePages[$measure['order']] = $this->document->getCurrentDocument()->musicalStructure[$measure['order']]['page'];

foreach ($measures as $measure) {
$measurePages[$measure['order']] = $this->document->getCurrentDocument()->musicalStructure[$measure['order']]['page'];
}
}

return $measurePages;
Expand Down
8 changes: 3 additions & 5 deletions Classes/Controller/PageViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,9 @@ protected function addViewerJS(): void
$currentMeasureId = '';
$docPage = $this->requestData['page'];

if ($this->document->getCurrentDocument() instanceof MetsDocument) {
$docMeasures = $this->getMeasures($docPage);
if ($this->requestData['measure']) {
$currentMeasureId = $docMeasures['measureCounterToMeasureId'][$this->requestData['measure']];
}
$docMeasures = $this->getMeasures($docPage);
if ($this->requestData['measure']) {
$currentMeasureId = $docMeasures['measureCounterToMeasureId'][$this->requestData['measure']];
}

// Viewer configuration.
Expand Down

0 comments on commit ff8c619

Please sign in to comment.