Skip to content

Commit

Permalink
Merge branch 'master' into two-level-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer authored Jun 12, 2023
2 parents e2258f1 + 4256816 commit fc4ceb7
Show file tree
Hide file tree
Showing 13 changed files with 355 additions and 230 deletions.
53 changes: 23 additions & 30 deletions Classes/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,36 +295,29 @@ protected function getParentDocumentUidForSaving(Document $document)
{
$doc = $document->getDoc();

if ($doc !== null) {
// Same as MetsDocument::parentHref (TODO: Use it)
// Get the closest ancestor of the current document which has a MPTR child.
$parentMptr = $doc->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $doc->toplevelId . '"]/ancestor::mets:div[./mets:mptr][1]/mets:mptr');
if (!empty($parentMptr)) {
$parentLocation = (string) $parentMptr[0]->attributes('http://www.w3.org/1999/xlink')->href;

// find document object by record_id of parent
$parentDoc = Doc::getInstance($parentLocation, ['storagePid' => $this->storagePid]);

if ($parentDoc->recordId) {
$parentDocument = $this->documentRepository->findOneByRecordId($parentDoc->recordId);

if ($parentDocument === null) {
// create new Document object
$parentDocument = GeneralUtility::makeInstance(Document::class);
}

$parentDocument->setOwner($this->owner);
$parentDocument->setDoc($parentDoc);
$parentDocument->setLocation($parentLocation);
$parentDocument->setSolrcore($document->getSolrcore());

$success = $this->saveToDatabase($parentDocument);

if ($success === true) {
// add to index
Indexer::add($parentDocument);
return $parentDocument->getUid();
}
if ($doc !== null && !empty($doc->parentHref)) {
// find document object by record_id of parent
$parentDoc = Doc::getInstance($doc->parentHref, ['storagePid' => $this->storagePid]);

if ($parentDoc->recordId) {
$parentDocument = $this->documentRepository->findOneByRecordId($parentDoc->recordId);

if ($parentDocument === null) {
// create new Document object
$parentDocument = GeneralUtility::makeInstance(Document::class);
}

$parentDocument->setOwner($this->owner);
$parentDocument->setDoc($parentDoc);
$parentDocument->setLocation($doc->parentHref);
$parentDocument->setSolrcore($document->getSolrcore());

$success = $this->saveToDatabase($parentDocument);

if ($success === true) {
// add to index
Indexer::add($parentDocument);
return $parentDocument->getUid();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions Classes/Common/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,9 @@ protected static function processLogical(Document $document, array $logicalUnit)
} elseif (preg_match("/^[\d]{8}$/", $metadata['date'][0])){
$solrDoc->setField('date', date("Y-m-d", strtotime($metadata['date'][0])));
// convert any datetime to proper ISO extended datetime format and timezone for SOLR
} else {
} elseif (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}T.*$/", $metadata['date'][0])) {
$solrDoc->setField('date', date('Y-m-d\TH:i:s\Z', strtotime($metadata['date'][0])));
}
$solrDoc->setField('date', $metadata['date'][0]);
}
$solrDoc->setField('record_id', $metadata['record_id'][0]);
$solrDoc->setField('purl', $metadata['purl'][0]);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ protected function _getToplevelId()
/**
* Try to determine URL of parent document.
*
* @return string|null
* @return string
*/
public function _getParentHref()
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/Common/SolrSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public function submit($start, $rows, $processResults = true)
$metadataOf = $this->fetchToplevelMetadataFromSolr([
'query' => 'partof:' . $doc['uid'],
'start' => 0,
'rows' => 100,
'rows' => 200,
]);
foreach ($children as $docChild) {
// We need only a few fields from the children, but we need them as array.
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ private function getMetadata()
// Get current structure's @ID.
$ids = [];
if (!empty($this->doc->physicalStructure[$this->requestData['page']]) && !empty($this->doc->smLinks['p2l'][$this->doc->physicalStructure[$this->requestData['page']]])) {
foreach ($this->doc->smLinks['p2l'][$doc->physicalStructure[$this->requestData['page']]] as $logId) {
$count = $doc->getStructureDepth($logId);
foreach ($this->doc->smLinks['p2l'][$this->doc->physicalStructure[$this->requestData['page']]] as $logId) {
$count = $this->doc->getStructureDepth($logId);
$ids[$count][] = $logId;
}
}
Expand Down
38 changes: 37 additions & 1 deletion Classes/Controller/TableOfContentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected function makeMenuArray()
}
}
}
$this->sortMenu($menuArray);
return $menuArray;
}

Expand All @@ -135,7 +136,7 @@ protected function getMenuEntry(array $entry, $recursive = false)
$entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel'];
$entryArray['volume'] = $entry['volume'];
$entryArray['orderlabel'] = $entry['orderlabel'];
$entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['storagePid']);
$entryArray['type'] = $this->getTranslatedType($entry['type']);
$entryArray['pagination'] = htmlspecialchars($entry['pagination']);
$entryArray['_OVERRIDE_HREF'] = '';
$entryArray['doNotLinkIt'] = 1;
Expand Down Expand Up @@ -237,4 +238,39 @@ protected function resolveMenuEntry($entry)

return $entry;
}

/**
* Get translated type of entry.
*
* @param array $type
* @return string
*/
private function getTranslatedType($type) {
return Helper::translate($type, 'tx_dlf_structures', $this->settings['storagePid']);
}

/**
* Sort menu by orderlabel - currently implemented for newspaper.
* //TODO: add for years
*
* @param array &$menu
* @return void
*/
private function sortMenu(&$menu) {
if ($menu[0]['type'] == $this->getTranslatedType("newspaper")) {
$this->sortMenuForNewspapers($menu);
}
}

/**
* Sort menu years of the newspaper by orderlabel.
*
* @param array &$menu
* @return void
*/
private function sortMenuForNewspapers(&$menu) {
usort($menu[0]['_SUB_MENU'], function ($firstYear, $secondYear) {
return $firstYear['orderlabel'] <=> $secondYear['orderlabel'];
});
}
}
9 changes: 8 additions & 1 deletion Classes/Controller/ToolboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,35 @@ private function renderTool() {
if (!empty($this->settings['tool'])) {
switch ($this->settings['tool']) {
case 'tx_dlf_annotationtool':
case 'annotationtool':
$this->renderToolByName('renderAnnotationTool');
break;
case 'tx_dlf_fulltextdownloadtool':
case 'fulltextdownloadtool':
$this->renderToolByName('renderFulltextDownloadTool');
break;
case 'tx_dlf_fulltexttool':
case 'fulltexttool':
$this->renderToolByName('renderFulltextTool');
break;
case 'tx_dlf_imagedownloadtool':
case 'imagedownloadtool':
$this->renderToolByName('renderImageDownloadTool');
break;
case 'tx_dlf_imagemanipulationtool':
case 'imagemanipulationtool':
$this->renderToolByName('renderImageManipulationTool');
break;
case 'tx_dlf_pdfdownloadtool':
case 'pdfdownloadtool':
$this->renderToolByName('renderPdfDownloadTool');
break;
case 'tx_dlf_searchindocumenttool':
case 'searchindocumenttool':
$this->renderToolByName('renderSearchInDocumentTool');
break;
default:
$this->logger->warn('Incorrect tool configuration: "' . $this->settings['tool'] . '". This tool does not exist.');
$this->logger->warning('Incorrect tool configuration: "' . $this->settings['tool'] . '". This tool does not exist.');
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions Configuration/FlexForms/Search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
</config>
</TCEforms>
</settings.fulltext>
<settings.fulltextPreselect>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.search.flexform.fulltextPreselect</label>
<config>
<type>check</type>
<default>0</default>
</config>
</TCEforms>
</settings.fulltextPreselect>
<settings.datesearch>
<TCEforms>
<exclude>1</exclude>
Expand Down
14 changes: 14 additions & 0 deletions Documentation/Plugins/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,20 @@ Search
:ref:`t3tsref:data-type-boolean`
:Default:

- :Property:
fulltextPreselect
:Data Type:
:ref:`t3tsref:data-type-boolean`
:Default:
0

- :Property:
datesearch
:Data Type:
:ref:`t3tsref:data-type-boolean`
:Default:
0

- :Property:
solrcore
:Data Type:
Expand Down
6 changes: 5 additions & 1 deletion Resources/Private/Language/de.locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,11 @@
</trans-unit>
<trans-unit id="plugins.search.flexform.fulltext" approved="yes">
<source><![CDATA[Enable full text search?]]></source>
<target><![CDATA[Volltext-Suche aktivieren?]]></target>
<target><![CDATA[Volltextsuche aktivieren?]]></target>
</trans-unit>
<trans-unit id="plugins.search.flexform.fulltextPreselect" approved="yes">
<source><![CDATA[Preselect full text search?]]></source>
<target><![CDATA[Volltextsuche vorauswählen?]]></target>
</trans-unit>
<trans-unit id="plugins.search.flexform.datesearch" approved="yes">
<source><![CDATA[Enable date search?]]></source>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<trans-unit id="plugins.search.flexform.fulltext">
<source><![CDATA[Enable full text search?]]></source>
</trans-unit>
<trans-unit id="plugins.search.flexform.fulltextPreselect">
<source><![CDATA[Preselect full text search?]]></source>
</trans-unit>
<trans-unit id="plugins.search.flexform.datesearch">
<source><![CDATA[Enable date search?]]></source>
</trans-unit>
Expand Down
20 changes: 16 additions & 4 deletions Resources/Private/Templates/Search/Main.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,22 @@

<!-- Fulltext switch -->
<f:if condition="{settings.fulltext}">
<f:form.radio property="fulltext" value="0" id="tx-dlf-search-fulltext-no-{viewData.uniqueId}" class="tx-dlf-search-fulltext" checked="{lastSearch.fulltext} == 0" />
<label for="tx-dlf-search-fulltext-no-{viewData.uniqueId}"><f:translate key="search.inMetadata"/></label>
<f:form.radio property="fulltext" value="1" id="tx-dlf-search-fulltext-yes-{viewData.uniqueId}" class="tx-dlf-search-fulltext-yes" checked="{lastSearch.fulltext} == 1" />
<label for="tx-dlf-search-fulltext-yes-{viewData.uniqueId}"><f:translate key="search.inFulltext"/></label>
<f:comment><!-- needs to be written like this, to check if fulltext searchparam == NULL --></f:comment>
<f:if condition="{lastSearch.fulltext} ==">
<f:then>
<f:form.radio property="fulltext" value="0" id="tx-dlf-search-fulltext-no-{viewData.uniqueId}" class="tx-dlf-search-fulltext" checked="{settings.fulltextPreselect} == 0" />
<label for="tx-dlf-search-fulltext-no-{viewData.uniqueId}"><f:translate key="search.inMetadata"/></label>
<f:form.radio property="fulltext" value="1" id="tx-dlf-search-fulltext-yes-{viewData.uniqueId}" class="tx-dlf-search-fulltext-yes" checked="{settings.fulltextPreselect} == 1" />
<label for="tx-dlf-search-fulltext-yes-{viewData.uniqueId}"><f:translate key="search.inFulltext"/></label>
</f:then>
<f:comment><!-- as soon we have a user preference, we use it instead --></f:comment>
<f:else>
<f:form.radio property="fulltext" value="0" id="tx-dlf-search-fulltext-no-{viewData.uniqueId}" class="tx-dlf-search-fulltext" checked="{lastSearch.fulltext} == 0" />
<label for="tx-dlf-search-fulltext-no-{viewData.uniqueId}"><f:translate key="search.inMetadata"/></label>
<f:form.radio property="fulltext" value="1" id="tx-dlf-search-fulltext-yes-{viewData.uniqueId}" class="tx-dlf-search-fulltext-yes" checked="{lastSearch.fulltext} == 1" />
<label for="tx-dlf-search-fulltext-yes-{viewData.uniqueId}"><f:translate key="search.inFulltext"/></label>
</f:else>
</f:if>
</f:if>

<f:comment><!-- Add list of collections as parameter when configured in search plugin --></f:comment>
Expand Down
Loading

0 comments on commit fc4ceb7

Please sign in to comment.