Skip to content

Commit

Permalink
[BUGFIX] Minor fixes in ToolboxController (#993)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
beatrycze-volk and sebastian-meyer authored Jul 21, 2023
1 parent 0869183 commit 38b64ca
Showing 1 changed file with 44 additions and 47 deletions.
91 changes: 44 additions & 47 deletions Classes/Controller/ToolboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Kitodo\Dlf\Controller;

use Kitodo\Dlf\Common\Helper;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

/**
* Controller class for plugin 'Toolbox'.
Expand Down Expand Up @@ -156,18 +156,7 @@ private function renderFulltextDownloadTool()
$this->setPage();

// Get text download.
$fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']);
while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->requestData['page']]]['files'][$fileGrpFulltext])) {
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->requestData['page']]]['files'][$fileGrpFulltext];
break;
}
}
if (!empty($fullTextFile)) {
$this->view->assign('fulltextDownload', true);
} else {
$this->view->assign('fulltextDownload', false);
}
$this->view->assign('fulltextDownload', !$this->isFullTextEmpty());
}

/**
Expand All @@ -189,14 +178,7 @@ private function renderFulltextTool()

$this->setPage();

$fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']);
while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->requestData['page']]]['files'][$fileGrpFulltext])) {
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->requestData['page']]]['files'][$fileGrpFulltext];
break;
}
}
if (!empty($fullTextFile)) {
if (!$this->isFullTextEmpty()) {
$this->view->assign('fulltext', true);
$this->view->assign('activateFullTextInitially', MathUtility::forceIntegerInRange($this->settings['activateFullTextInitially'], 0, 1, 0));
} else {
Expand Down Expand Up @@ -245,12 +227,13 @@ private function getImage($page)
{
$image = [];
// Get @USE value of METS fileGrp.
$fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload']);
$fileGrps = GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload']);
while ($fileGrp = @array_pop($fileGrps)) {
// Get image link.
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp])) {
$image['url'] = $this->doc->getDownloadLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
$image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]);
$fileGroup = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp];
if (!empty($fileGroup)) {
$image['url'] = $this->doc->getDownloadLocation($fileGroup);
$image['mimetype'] = $this->doc->getFileMimeType($fileGroup);
switch ($image['mimetype']) {
case 'image/jpeg':
$image['mimetypeLabel'] = ' (JPG)';
Expand Down Expand Up @@ -319,38 +302,40 @@ private function renderPdfDownloadTool()
*/
private function getPageLink()
{
$page1Link = '';
$page2Link = '';
$firstPageLink = '';
$secondPageLink = '';
$pageLinkArray = [];
$pageNumber = $this->requestData['page'];
$fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']);
// Get image link.
while ($fileGrpDownload = array_shift($fileGrpsDownload)) {
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]['files'][$fileGrpDownload])) {
$page1Link = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]['files'][$fileGrpDownload]);
$firstFileGroupDownload = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber]]['files'][$fileGrpDownload];
if (!empty($firstFileGroupDownload)) {
$firstPageLink = $this->doc->getFileLocation($firstFileGroupDownload);
// Get second page, too, if double page view is activated.
$secondFileGroupDownload = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload];
if (
$this->requestData['double']
&& $pageNumber < $this->doc->numPages
&& !empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload])
&& !empty($secondFileGroupDownload)
) {
$page2Link = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload]);
$secondPageLink = $this->doc->getFileLocation($secondFileGroupDownload);
}
break;
}
}
if (
empty($page1Link)
&& empty($page2Link)
empty($firstPageLink)
&& empty($secondPageLink)
) {
$this->logger->warning('File not found in fileGrps "' . $this->extConf['fileGrpDownload'] . '"');
}

if (!empty($page1Link)) {
$pageLinkArray[0] = $page1Link;
if (!empty($firstPageLink)) {
$pageLinkArray[0] = $firstPageLink;
}
if (!empty($page2Link)) {
$pageLinkArray[1] = $page2Link;
if (!empty($secondPageLink)) {
$pageLinkArray[1] = $secondPageLink;
}
return $pageLinkArray;
}
Expand All @@ -368,8 +353,9 @@ private function getWorkLink()
$fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']);
// Get work link.
while ($fileGrpDownload = array_shift($fileGrpsDownload)) {
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$fileGrpDownload])) {
$workLink = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$fileGrpDownload]);
$fileGroupDownload = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[0]]['files'][$fileGrpDownload];
if (!empty($fileGroupDownload)) {
$workLink = $this->doc->getFileLocation($fileGroupDownload);
break;
} else {
$details = $this->doc->getLogicalStructure($this->doc->toplevelId);
Expand Down Expand Up @@ -406,14 +392,7 @@ private function renderSearchInDocumentTool()
$this->setPage();

// Quit if no fulltext file is present
$fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']);
while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->requestData['page']]]['files'][$fileGrpFulltext])) {
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->requestData['page']]]['files'][$fileGrpFulltext];
break;
}
}
if (empty($fullTextFile)) {
if ($this->isFullTextEmpty()) {
return;
}

Expand Down Expand Up @@ -487,4 +466,22 @@ private function getEncryptedCoreName()
}
return $name;
}

/**
* Check if the full text is empty.
*
* @access private
*
* @return bool true if empty, false otherwise
*/
private function isFullTextEmpty() {
$fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['fileGrpFulltext']);
while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) {
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->requestData['page']]]['files'][$fileGrpFulltext];
if (!empty($fullTextFile)) {
break;
}
}
return empty($fullTextFile);
}
}

0 comments on commit 38b64ca

Please sign in to comment.