diff --git a/Classes/Common/DocumentAnnotation.php b/Classes/Common/DocumentAnnotation.php index a3bcecb7f..d4ca9e829 100644 --- a/Classes/Common/DocumentAnnotation.php +++ b/Classes/Common/DocumentAnnotation.php @@ -77,38 +77,40 @@ function getAnnotations() { if ($annotationTarget->getId()) { if ($this->document->getCurrentDocument()->getFileLocation($annotationTarget->getId())) { - if ( - $meiTargetPages = $this->getMeasurePagesByFileId( - $annotationTarget->getId(), $annotationTarget->getRangeValue() - ) - ) { - $targetPages[] = [ - 'target' => $annotationTarget, - 'pages' => $meiTargetPages, - 'verovioRelevant' => true - ]; - - } elseif ( - $audioTargetPages = $this->getAudioPagesByFileId( - $annotationTarget->getId(), $annotationTarget->getRangeValue() - ) - ) { - $targetPages[] = [ - 'target' => $annotationTarget, - 'pages' => $audioTargetPages - ]; - - } elseif ($fileIdTargetPages = $this->getPagesByFileId($annotationTarget->getId())) { - $targetPages[] = [ - 'target' => $annotationTarget, - 'pages' => $fileIdTargetPages - ]; - - } else { - $this->logger->warning( - ' No target pages found! Annotation: "' . $annotation->getId() . '", ' - . 'Target: "' . $annotationTarget->getUrl() . '"' - ); + if ($this->document->getCurrentDocument() instanceof MetsDocument) { + if ( + $meiTargetPages = $this->getMeasurePagesByFileId( + $annotationTarget->getId(), $annotationTarget->getRangeValue() + ) + ) { + $targetPages[] = [ + 'target' => $annotationTarget, + 'pages' => $meiTargetPages, + 'verovioRelevant' => true + ]; + + } elseif ( + $audioTargetPages = $this->getAudioPagesByFileId( + $annotationTarget->getId(), $annotationTarget->getRangeValue() + ) + ) { + $targetPages[] = [ + 'target' => $annotationTarget, + 'pages' => $audioTargetPages + ]; + + } elseif ($fileIdTargetPages = $this->getPagesByFileId($annotationTarget->getId())) { + $targetPages[] = [ + 'target' => $annotationTarget, + 'pages' => $fileIdTargetPages + ]; + + } else { + $this->logger->warning( + ' No target pages found! Annotation: "' . $annotation->getId() . '", ' + . 'Target: "' . $annotationTarget->getUrl() . '"' + ); + } } } elseif ($logicalTargetPages = $this->getPagesByLogicalId($annotationTarget->getId())) { $targetPages[] = [ @@ -322,6 +324,8 @@ protected function getMeasurePagesByFileId($fileId, $range = null) $measureIndex = 1; $startOrder = 0; $endOrder = 0; + + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument foreach ($this->document->getCurrentDocument()->musicalStructureInfo as $key => $musicalInfo) { if ($musicalInfo['type'] === 'measure' && is_array($musicalInfo['files'])) { foreach ($musicalInfo['files'] as $file) { @@ -368,6 +372,7 @@ protected function getMeasurePagesByFileId($fileId, $range = null) // Get the related page numbers $measurePages = []; foreach ($measures as $measure) { + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument $measurePages[$measure['order']] = $this->document->getCurrentDocument()->musicalStructure[$measure['order']]['page']; } @@ -405,7 +410,8 @@ protected static function loadData($document) $conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); $apiBaseUrl = $conf['annotationServerUrl']; - if ($apiBaseUrl) { + if ($apiBaseUrl && $document->getCurrentDocument() instanceof MetsDocument) { + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument $purl = $document->getCurrentDocument()->mets->xpath('//mods:mods/mods:identifier[@type="purl"]'); if (count($purl) > 0) { $annotationRequest = new AnnotationRequest($apiBaseUrl); diff --git a/Classes/Controller/NavigationController.php b/Classes/Controller/NavigationController.php index 8099183c6..d95005b81 100644 --- a/Classes/Controller/NavigationController.php +++ b/Classes/Controller/NavigationController.php @@ -11,6 +11,7 @@ namespace Kitodo\Dlf\Controller; +use Kitodo\Dlf\Common\MetsDocument; use Kitodo\Dlf\Domain\Model\PageSelectForm; use TYPO3\CMS\Core\Utility\MathUtility; @@ -116,24 +117,31 @@ public function mainAction(): void } $this->view->assign('features', $features); - if ($this->document->getCurrentDocument()->numMeasures > 0) { - $measureOptions = []; - $measurePages = []; - for ($i = 1; $i <= $this->document->getCurrentDocument()->numMeasures; $i++) { - $measureOptions[$i] = '[' . $i . ']' . ($this->document->getCurrentDocument()->musicalStructureInfo[$this->document->getCurrentDocument()->musicalStructure[$i]['measureid']]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getCurrentDocument()->musicalStructureInfo[$this->document->getCurrentDocument()->musicalStructureInfo[$i]]['orderlabel']) : ''); - $measurePages[$i] = $this->document->getCurrentDocument()->musicalStructure[$i]['page']; + if ($this->document->getCurrentDocument() instanceof MetsDocument) { + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument + if ($this->document->getCurrentDocument()->numMeasures > 0) { + $measureOptions = []; + $measurePages = []; + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument + for ($i = 1; $i <= $this->document->getCurrentDocument()->numMeasures; $i++) { + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument + $measureOptions[$i] = '[' . $i . ']' . ($this->document->getCurrentDocument()->musicalStructureInfo[$this->document->getCurrentDocument()->musicalStructure[$i]['measureid']]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getCurrentDocument()->musicalStructureInfo[$this->document->getCurrentDocument()->musicalStructureInfo[$i]]['orderlabel']) : ''); + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument + $measurePages[$i] = $this->document->getCurrentDocument()->musicalStructure[$i]['page']; + } + + if (!isset($this->requestData['measure'])) { + $currentMeasure = array_search($this->requestData['page'], $measurePages); + } else { + $currentMeasure = $this->requestData['measure']; + } + + $this->view->assign('currentMeasure', $currentMeasure); + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument + $this->view->assign('numMeasures', $this->document->getCurrentDocument()->numMeasures); + $this->view->assign('measureOptions', $measureOptions); + $this->view->assign('measurePages', $measurePages); } - - if (!isset($this->requestData['measure'])) { - $currentMeasure = array_search($this->requestData['page'], $measurePages); - } else { - $currentMeasure = $this->requestData['measure']; - } - - $this->view->assign('currentMeasure', $currentMeasure); - $this->view->assign('numMeasures', $this->document->getCurrentDocument()->numMeasures); - $this->view->assign('measureOptions', $measureOptions); - $this->view->assign('measurePages', $measurePages); } } } diff --git a/Classes/Controller/PageViewController.php b/Classes/Controller/PageViewController.php index 3d2cb289a..f87c870b7 100644 --- a/Classes/Controller/PageViewController.php +++ b/Classes/Controller/PageViewController.php @@ -14,6 +14,8 @@ use Kitodo\Dlf\Common\AbstractDocument; use Kitodo\Dlf\Common\DocumentAnnotation; use Kitodo\Dlf\Common\IiifManifest; +use Kitodo\Dlf\Common\MetsDocument; +use Kitodo\Dlf\Domain\Model\Document; use Kitodo\Dlf\Domain\Model\FormAddDocument; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; @@ -127,9 +129,10 @@ public function mainAction(): void $this->fulltexts[1] = $this->getFulltext($this->requestData['page'] + 1); $this->annotationContainers[1] = $this->getAnnotationContainers($this->requestData['page'] + 1); } - $this->scores = $this->getScore($this->requestData['page']); - - $this->measures = $this->getMeasures($this->requestData['page']); + if ($this->document->getCurrentDocument() instanceof MetsDocument) { + $this->scores = $this->getScore($this->requestData['page']); + $this->measures = $this->getMeasures($this->requestData['page']); + } // Get the controls for the map. $this->controls = explode(',', $this->settings['features']); @@ -297,10 +300,11 @@ public function addDocumentAction(FormAddDocument $formAddDocument) /** * Get all measures from musical struct * @param int $page - * @param ?AbstractDocument $specificDoc + * @param ?Document $specificDoc + * @param int|null $docNumber * @return array */ - protected function getMeasures(int $page, $specificDoc = null, $docNumber = null): array + protected function getMeasures(int $page, Document $specificDoc = null, $docNumber = null): array { if ($specificDoc) { $doc = $specificDoc; @@ -313,6 +317,7 @@ protected function getMeasures(int $page, $specificDoc = null, $docNumber = null $measureLinks = []; $defaultFileId = $doc->physicalStructureInfo[$currentPhysId]['files']['DEFAULT']; if (isset($defaultFileId)) { + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument $musicalStruct = $doc->musicalStructureInfo; $i = 0; @@ -358,11 +363,11 @@ protected function getMeasures(int $page, $specificDoc = null, $docNumber = null * @access protected * * @param int $page: Page number - * @param ?MetsDocument $specificDoc + * @param ?Document $specificDoc * * @return array URL and MIME type of fulltext file */ - protected function getScore(int $page, $specificDoc = null) + protected function getScore(int $page, Document $specificDoc = null) { $score = []; $loc = ''; @@ -385,6 +390,7 @@ protected function getScore(int $page, $specificDoc = null) if (!empty($loc)) { $score['mimetype'] = $doc->getFileMimeType($loc); + // @phpstan-ignore-next-line It is ensured that getCurrentDocument returns a MetsDocument $score['pagebeginning'] = $doc->getPageBeginning($pageId, $loc); $score['url'] = $doc->getFileLocation($loc); if ($this->settings['useInternalProxy']) { @@ -602,11 +608,11 @@ protected function getAnnotationContainers(int $page): array * * @param int $page Page number * - * @param ?AbstractDocument $specificDoc + * @param ?Document $specificDoc * * @return array URL and MIME type of image file */ - protected function getImage(int $page, $specificDoc = null): array + protected function getImage(int $page, Document $specificDoc = null): array { $image = []; // Get @USE value of METS fileGrp.