Skip to content

Commit b255c25

Browse files
Merge branch '5.0.x' into fix-documentpageid-in-toolboxcontroller
2 parents 2afaacc + 8fc8bf3 commit b255c25

File tree

9 files changed

+77
-42
lines changed

9 files changed

+77
-42
lines changed

Classes/Command/BaseCommand.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,29 +230,29 @@ protected function saveToDatabase(Document $document): bool
230230
}
231231

232232
// set identifiers
233-
$document->setProdId($metadata['prod_id'][0] ? : '');
234-
$document->setOpacId($metadata['opac_id'][0] ? : '');
235-
$document->setUnionId($metadata['union_id'][0] ? : '');
233+
$document->setProdId($metadata['prod_id'][0] ?? '');
234+
$document->setOpacId($metadata['opac_id'][0] ?? '');
235+
$document->setUnionId($metadata['union_id'][0] ?? '');
236236

237-
$document->setRecordId($metadata['record_id'][0] ? : ''); // (?) $doc->recordId
238-
$document->setUrn($metadata['urn'][0] ? : '');
239-
$document->setPurl($metadata['purl'][0] ? : '');
240-
$document->setDocumentFormat($metadata['document_format'][0] ? : '');
237+
$document->setRecordId($metadata['record_id'][0] ?? ''); // (?) $doc->recordId
238+
$document->setUrn($metadata['urn'][0] ?? '');
239+
$document->setPurl($metadata['purl'][0] ?? '');
240+
$document->setDocumentFormat($metadata['document_format'][0] ?? '');
241241

242242
// set access
243-
$document->setLicense($metadata['license'][0] ? : '');
244-
$document->setTerms($metadata['terms'][0] ? : '');
245-
$document->setRestrictions($metadata['restrictions'][0] ? : '');
246-
$document->setOutOfPrint($metadata['out_of_print'][0] ? : '');
247-
$document->setRightsInfo($metadata['rights_info'][0] ? : '');
243+
$document->setLicense($metadata['license'][0] ?? '');
244+
$document->setTerms($metadata['terms'][0] ?? '');
245+
$document->setRestrictions($metadata['restrictions'][0] ?? '');
246+
$document->setOutOfPrint($metadata['out_of_print'][0] ?? '');
247+
$document->setRightsInfo($metadata['rights_info'][0] ?? '');
248248
$document->setStatus(0);
249249

250-
$this->setOwner($metadata['owner'][0]);
250+
$this->setOwner($metadata['owner'][0] ?? '');
251251
$document->setOwner($this->owner);
252252

253253
// set volume data
254-
$document->setVolume($metadata['volume'][0] ? : '');
255-
$document->setVolumeSorting($metadata['volume_sorting'][0] ? : $metadata['mets_order'][0] ? : '');
254+
$document->setVolume($metadata['volume'][0] ?? '');
255+
$document->setVolumeSorting($metadata['volume_sorting'][0] ?? $metadata['mets_order'][0] ?? '');
256256

257257
// Get UID of parent document.
258258
if ($document->getDocumentFormat() === 'METS') {
@@ -290,7 +290,7 @@ protected function getParentDocumentUidForSaving(Document $document): int
290290
// find document object by record_id of parent
291291
$parent = AbstractDocument::getInstance($doc->parentHref, ['storagePid' => $this->storagePid]);
292292

293-
if ($parent->recordId) {
293+
if ($parent && $parent->recordId) {
294294
$parentDocument = $this->documentRepository->findOneByRecordId($parent->recordId);
295295

296296
if ($parentDocument === null) {

Classes/Command/IndexCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private function getDocumentFromUrl($doc, string $url): Document
210210
{
211211
$document = null;
212212

213-
if ($doc->recordId) {
213+
if ($doc and $doc->recordId) {
214214
$document = $this->documentRepository->findOneByRecordId($doc->recordId);
215215
} else {
216216
$document = $this->documentRepository->findOneByLocation($url);

Classes/Common/MetsDocument.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,18 @@ private function getThumbnail(string $id = '')
435435

436436
$thumbnail = null;
437437

438-
while ($fileGrpThumb = array_shift($fileGrpsThumb)) {
439-
if (empty($id)) {
440-
$thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb] ?? null;
441-
} else {
442-
$parentId = $this->smLinks['l2p'][$id][0] ?? null;
443-
$thumbnail = $this->physicalStructureInfo[$parentId]['files'][$fileGrpThumb] ?? null;
444-
}
438+
if (!empty($this->physicalStructure)) {
439+
while ($fileGrpThumb = array_shift($fileGrpsThumb)) {
440+
if (empty($id)) {
441+
$thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb] ?? null;
442+
} else {
443+
$parentId = $this->smLinks['l2p'][$id][0] ?? null;
444+
$thumbnail = $this->physicalStructureInfo[$parentId]['files'][$fileGrpThumb] ?? null;
445+
}
445446

446-
if (!empty($thumbnail)) {
447-
break;
447+
if (!empty($thumbnail)) {
448+
break;
449+
}
448450
}
449451
}
450452
return $thumbnail;
@@ -1416,7 +1418,10 @@ protected function magicGetThumbnail(bool $forceReload = false): string
14161418
) {
14171419
$this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$fileGrpThumb]);
14181420
break;
1419-
} elseif (!empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb])) {
1421+
} elseif (
1422+
!empty($this->physicalStructure)
1423+
&& !empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb])
1424+
) {
14201425
$this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb]);
14211426
break;
14221427
}

Classes/Controller/MetadataController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ private function getMetadata(): array
464464
if ($this->settings['rootline'] < 2) {
465465
// Get current structure's @ID.
466466
$ids = [];
467-
$page = $this->currentDocument->physicalStructure[$this->requestData['page']];
467+
$page = $this->currentDocument->physicalStructure[$this->requestData['page']] ?? [];
468468
if (!empty($page) && !empty($this->currentDocument->smLinks['p2l'][$page])) {
469469
foreach ($this->currentDocument->smLinks['p2l'][$page] as $logId) {
470470
$count = $this->currentDocument->getStructureDepth($logId);

Classes/Controller/OaiPmhController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function mainAction()
273273
// Delete expired resumption tokens.
274274
$this->deleteExpiredTokens();
275275

276-
switch ($this->parameters['verb']) {
276+
switch ($this->parameters['verb'] ?? null) {
277277
case 'GetRecord':
278278
$this->verbGetRecord();
279279
break;

Classes/Domain/Repository/CollectionRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public function findCollectionsBySettings(array $settings = []): QueryResultInte
9797

9898
$constraints = [];
9999

100-
if ($settings['collections']) {
100+
if ($settings['collections'] ?? false) {
101101
$constraints[] = $query->in('uid', GeneralUtility::intExplode(',', $settings['collections']));
102102
}
103103

104-
if ($settings['index_name']) {
104+
if ($settings['index_name'] ?? false) {
105105
$constraints[] = $query->in('index_name', $settings['index_name']);
106106
}
107107

Resources/Public/JavaScript/PageView/PageView.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,18 @@ dlfViewer.prototype.createControl = function(controlName, layers) {
439439
}
440440
};
441441

442+
/**
443+
* Forwards the search to dlfUtils.searchFeatureCollectionForWords
444+
*
445+
* @param {Array.<ol.Feature>} stringFeatures - Array of features containing text information
446+
* @param {string} value - Search term
447+
* @returns {Array.<ol.Feature>|undefined} Array of OpenLayers features containing found words
448+
* @see dlfUtils.searchFeatureCollectionForWords
449+
*/
450+
dlfViewer.prototype.searchFeatures = function(stringFeatures, value) {
451+
return dlfUtils.searchFeatureCollectionForWords(stringFeatures, value);
452+
};
453+
442454
/**
443455
* Displays highlight words
444456
*/
@@ -491,23 +503,23 @@ dlfViewer.prototype.displayHighlightWord = function(highlightWords = null) {
491503
}
492504

493505
if (this.highlightWords !== null) {
494-
var self = this;
495-
var values = decodeURIComponent(this.highlightWords).split(';');
506+
const self = this;
507+
const values = decodeURIComponent(this.highlightWords).split(';');
496508

497509
$.when.apply($, this.fulltextsLoaded_)
498-
.done(function (fulltextData, fulltextDataImageTwo) {
499-
var stringFeatures = [];
510+
.done((fulltextData, fulltextDataImageTwo) => {
511+
const stringFeatures = [];
500512

501-
[fulltextData, fulltextDataImageTwo].forEach(function (data) {
513+
[fulltextData, fulltextDataImageTwo].forEach(data => {
502514
if (data !== undefined) {
503515
Array.prototype.push.apply(stringFeatures, data.getStringFeatures());
504516
}
505517
});
506518

507-
values.forEach(function(value) {
508-
var features = dlfUtils.searchFeatureCollectionForCoordinates(stringFeatures, value);
519+
values.forEach((value) => {
520+
const features = this.searchFeatures(stringFeatures, value);
509521
if (features !== undefined) {
510-
for (var i = 0; i < features.length; i++) {
522+
for (let i = 0; i < features.length; i++) {
511523
self.highlightLayer.getSource().addFeatures([features[i]]);
512524
}
513525
}

Resources/Public/JavaScript/PageView/SearchInDocument.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ $(document).ready(function() {
277277
"json"
278278
)
279279
.done(function (data) {
280-
$('#tx-dfgviewer-sru-results-loading').hide();
281-
$('#tx-dfgviewer-sru-results-clearing').show();
280+
$('#tx-dlf-search-in-document-loading').hide();
281+
$('#tx-dlf-search-in-document-clearing').show();
282282
});
283283
});
284284

Resources/Public/JavaScript/PageView/Utility.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,31 @@ dlfUtils.scaleToImageSize = function (features, imageObj, width, height, optOffs
646646
return features;
647647
};
648648

649+
/**
650+
* Search a feature collection for a feature with the given coordinates
651+
* @param {Array.<ol.Feature>} featureCollection
652+
* @param {string} coordinates for highlighting
653+
* @returns {Array.<ol.Feature>|undefined}
654+
*/
655+
dlfUtils.searchFeatureCollectionForCoordinates = function (featureCollection, coordinates) {
656+
var features = [];
657+
featureCollection.forEach(function (ft) {
658+
if (ft.get('fulltext') !== undefined) {
659+
if (ft.getId() === coordinates) {
660+
features.push(ft);
661+
}
662+
}
663+
});
664+
return features.length > 0 ? features : undefined;
665+
};
666+
649667
/**
650668
* Search a feature collection for a feature with the given word in its fulltext
651669
* @param {Array.<ol.Feature>} featureCollection
652670
* @param {string} word for highlighting
653671
* @returns {Array.<ol.Feature>|undefined}
654672
*/
655-
dlfUtils.searchFeatureCollectionForCoordinates = function (featureCollection, word) {
673+
dlfUtils.searchFeatureCollectionForWords = function (featureCollection, word) {
656674
var features = [];
657675
featureCollection.forEach(function (ft) {
658676
if (ft.values_.fulltext !== undefined) {

0 commit comments

Comments
 (0)