Adds the feature to enter a logical page in addition to the search term.

With this feature you can configure the search plugin to show an
additional field for the logical page. The page view plugin then opens
the document on the page with the first occurance of the entered logical
page within the page label.
This commit is contained in:
Frank Ulrich Weber 2017-11-17 15:47:40 +01:00
parent efb3631f1d
commit 7a67a0257e
13 changed files with 186 additions and 6 deletions

View File

@ -115,6 +115,14 @@ final class tx_dlf_document {
*/
protected $hasFulltext = FALSE;
/**
* Last searched logical and physical page
*
* @var array
* @access protected
*/
protected $lastSearchedPhysicalPage = array ('logicalPage' => NULL, 'physicalPage' => NULL);
/**
* This holds the documents location
*
@ -898,6 +906,46 @@ final class tx_dlf_document {
}
/**
* This returns the first corresponding physical page number of a given logical page label
*
* @access public
*
* @param string $logicalPage: The label (or a part of the label) of the logical page
*
* @return integer The physical page number
*/
public function getPhysicalPage($logicalPage) {
if(!empty( $this->lastSearchedPhysicalPage['logicalPage']) && $this->lastPhysicalPageSearch['logicalPage'] == $logicalPage) {
return $this->lastSearchedPhysicalPage['physicalPage'];
} else {
$physicalPage = 0;
foreach($this->physicalStructureInfo as $page) {
if(strpos($page['orderlabel'], $logicalPage) !== false){
$this->lastSearchedPhysicalPage['logicalPage'] = $logicalPage;
$this->lastSearchedPhysicalPage['physicalPage'] = $physicalPage;
return $physicalPage;
}
$physicalPage++;
}
}
return 1;
}
/**
* This determines a title for the given document
*

View File

@ -193,6 +193,12 @@ class tx_dlf_listview extends tx_dlf_plugin {
'page' => $this->list[$number]['page']
);
if(!empty($this->piVars['logicalPage'])) {
$additionalParams['logicalPage'] = $this->piVars['logicalPage'];
}
$conf = array (
'useCacheHash' => 1,
'parameter' => $this->conf['targetPid'],
@ -293,6 +299,12 @@ class tx_dlf_listview extends tx_dlf_plugin {
'forceAbsoluteUrl' => 1
);
if(!empty($this->piVars['logicalPage'])) {
$linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId,array('logicalPage' => $this->piVars['logicalPage']), '', TRUE, FALSE);
}
// Build HTML form.
$sorting = '<form action="'.$this->cObj->typoLink_URL($linkConf).'" method="get"><div><input type="hidden" name="id" value="'.$GLOBALS['TSFE']->id.'" />';
@ -406,6 +418,12 @@ class tx_dlf_listview extends tx_dlf_plugin {
'highlight_word' => preg_replace('/\s\s+/', ';', $this->list->metadata['searchString'])
);
if(!empty($this->piVars['logicalPage'])) {
$additionalParams['logicalPage'] = $this->piVars['logicalPage'];
}
$conf = array (
// we don't want cHash in case of search parameters
'useCacheHash' => empty($this->list->metadata['searchString']) ? 1 : 0,

View File

@ -129,6 +129,13 @@ class tx_dlf_navigation extends tx_dlf_plugin {
// Set default values if not set.
if ($this->doc->numPages > 0) {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
unset($this->piVars['logicalPage']);
}
// Set default values if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {

View File

@ -223,6 +223,13 @@ class tx_dlf_pagegrid extends tx_dlf_plugin {
}
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
unset($this->piVars['logicalPage']);
}
// Set some variable defaults.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {

View File

@ -222,6 +222,13 @@ class tx_dlf_pageview extends tx_dlf_plugin {
} else {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
unset($this->piVars['logicalPage']);
}
// Set default values if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {

View File

@ -321,6 +321,30 @@ class tx_dlf_search extends tx_dlf_plugin {
}
/**
* Adds the logical page field to the search form
*
* @access protected
*
* @return string HTML output of logical page field
*/
protected function addLogicalPage() {
$output = '';
// Check for plugin configuration.
if (!empty($this->conf['showLogicalPageField'])) {
$output .= ' <label for="tx-dlf-search-logical-page">' . $this->pi_getLL('label.logicalPage', '') . ': </label>';
$output .= ' <input class="tx-dlf-search-logical-page" id="tx-dlf-search-logical-page" type="text" name="' . $this->prefixId . '[logicalPage]" />';
}
return $output;
}
/**
* Creates an array for a HMENU entry of a facet value.
*
@ -487,7 +511,8 @@ class tx_dlf_search extends tx_dlf_plugin {
'###FIELD_DOC###' => ($this->conf['searchIn'] == 'document' || $this->conf['searchIn'] == 'all' ? $this->addCurrentDocument() : ''),
'###FIELD_COLL###' => ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all' ? $this->addCurrentCollection() : ''),
'###ADDITIONAL_INPUTS###' => $this->addEncryptedCoreName(),
'###FACETS_MENU###' => $this->addFacetsMenu()
'###FACETS_MENU###' => $this->addFacetsMenu(),
'###LOGICAL_PAGE###' => $this->addLogicalPage()
);
// Get additional fields for extended search.
@ -657,13 +682,24 @@ class tx_dlf_search extends tx_dlf_plugin {
// Keep some plugin variables.
$linkConf['parameter'] = $this->conf['targetPid'];
$additionalParams = array();
if(!empty($this->piVars['logicalPage'])) {
$additionalParams['logicalPage'] = $this->piVars['logicalPage'];
}
if (!empty($this->piVars['order'])) {
$linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId,
array (
'order' => $this->piVars['order'],
'asc' => (!empty($this->piVars['asc']) ? '1' : '0')
), '', TRUE, FALSE);
$additionalParams['order'] = $this->piVars['order'];
$additionalParams['asc'] = !empty($this->piVars['asc']) ? '1' : '0';
}
if(count($additionalParams)) {
$linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId,$additionalParams, '', TRUE, FALSE);
}

View File

@ -220,6 +220,16 @@
</config>
</TCEforms>
</suggest>
<showLogicalPageField>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.showLogicalPageField</label>
<config>
<type>check</type>
<default>0</default>
</config>
</TCEforms>
</showLogicalPageField>
<targetPid>
<TCEforms>
<exclude>1</exclude>
@ -240,6 +250,20 @@
</config>
</TCEforms>
</targetPid>
<targetPidPageView>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.targetPidPageView</label>
<config>
<type>group</type>
<internal_type>db</internal_type>
<allowed>pages</allowed>
<size>1</size>
<maxitems>1</maxitems>
<minitems>1</minitems>
</config>
</TCEforms>
</targetPidPageView>
<templateFile>
<TCEforms>
<exclude>1</exclude>

View File

@ -36,10 +36,12 @@
<label index="tt_content.pi_flexform.targetPid">Target page (with "DLF: List View" plugin)</label>
<label index="tt_content.pi_flexform.separator">Separator for metadata in TS array</label>
<label index="tt_content.pi_flexform.templateFile">Template file</label>
<label index="tt_content.pi_flexform.showLogicalPageField">Show field for logical page?</label>
<label index="label.query">Search for:</label>
<label index="label.submit">Search</label>
<label index="label.inFulltext">in fulltext</label>
<label index="label.inMetadata">in metadata</label>
<label index="label.logicalPage">Page</label>
<label index="search">Search</label>
<label index="for"> for "%s"</label>
<label index="in"> in "%s"</label>
@ -71,10 +73,12 @@
<label index="tt_content.pi_flexform.targetPid">Zielseite (mit Plugin "DLF: Listenansicht")</label>
<label index="tt_content.pi_flexform.separator">Trennzeichen für Metadaten im TS-Array</label>
<label index="tt_content.pi_flexform.templateFile">HTML-Template</label>
<label index="tt_content.pi_flexform.showLogicalPageField">Feld für logische Seite anzeigen?</label>
<label index="label.query">Suchen nach:</label>
<label index="label.submit">Suchen</label>
<label index="label.inFulltext">im Volltext</label>
<label index="label.inMetadata">in Metadaten</label>
<label index="label.logicalPage">Seite</label>
<label index="search">Suche</label>
<label index="for"> nach "%s"</label>
<label index="in"> in "%s"</label>

View File

@ -12,6 +12,7 @@
<label for="tx-dlf-search-query">###LABEL_QUERY###</label>
<!-- Never change the @id of this input field! Otherwise search suggestions won't work! -->
<input type="text" id="tx-dlf-search-query" name="###FIELD_QUERY###" value="###QUERY###" />
###LOGICAL_PAGE###
<!-- The following element is needed for auto-completion! -->
<div id="tx-dlf-search-suggest"></div>
<input type="submit" value="###LABEL_SUBMIT###" />

View File

@ -202,6 +202,13 @@ class tx_dlf_toc extends tx_dlf_plugin {
} else {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
unset($this->piVars['logicalPage']);
}
// Set default values for page if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {

View File

@ -49,6 +49,13 @@ class tx_dlf_toolsFulltext extends tx_dlf_plugin {
} else {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
unset($this->piVars['logicalPage']);
}
// Set default values if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {

View File

@ -48,6 +48,13 @@ class tx_dlf_toolsImagedownload extends tx_dlf_plugin {
} else {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
unset($this->piVars['logicalPage']);
}
// Set default values if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {

View File

@ -49,6 +49,13 @@ class tx_dlf_toolsPdf extends tx_dlf_plugin {
} else {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
unset($this->piVars['logicalPage']);
}
// Set default values if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {