From 8521ef81fad66de0ca44292858470cda31ebef25 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Thu, 6 Sep 2012 13:04:11 +0200 Subject: [PATCH] Refactor in-collection searching --- dlf/common/class.tx_dlf_helper.php | 2 +- dlf/plugins/search/class.tx_dlf_search.php | 34 ++++++++++++++++++---- dlf/plugins/search/template.tmpl | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/dlf/common/class.tx_dlf_helper.php b/dlf/common/class.tx_dlf_helper.php index 430e1b98..0e39f62b 100644 --- a/dlf/common/class.tx_dlf_helper.php +++ b/dlf/common/class.tx_dlf_helper.php @@ -881,7 +881,7 @@ class tx_dlf_helper { * @param string $table: Get the translation from this table * @param string $pid: Get the translation from this page * - * @return mixed Translated label or boolean value if $checkOnly is set + * @return string Localized label for $index_name */ public static function translate($index_name, $table, $pid) { diff --git a/dlf/plugins/search/class.tx_dlf_search.php b/dlf/plugins/search/class.tx_dlf_search.php index eae8eda2..d829644c 100644 --- a/dlf/plugins/search/class.tx_dlf_search.php +++ b/dlf/plugins/search/class.tx_dlf_search.php @@ -75,7 +75,30 @@ class tx_dlf_search extends tx_dlf_plugin { } /** - * Adds the current document's UID and parent ID to the search form + * Adds the current collection's UID to the search form + * + * @access protected + * + * @return string HTML input fields with current document's UID and parent ID + */ + protected function addCurrentCollection() { + + // Load current collection. + $list = t3lib_div::makeInstance('tx_dlf_list'); + + if (!empty($list->metadata['options']['source']) && $list->metadata['options']['source'] == 'collection') { + + // Get collection's UID. + return ''; + + } + + return ''; + + } + + /** + * Adds the current document's UID or parent ID to the search form * * @access protected * @@ -328,6 +351,7 @@ class tx_dlf_search extends tx_dlf_plugin { '###FIELD_QUERY###' => $this->prefixId.'[query]', '###QUERY###' => htmlspecialchars($lastQuery), '###FIELD_DOC###' => $this->addCurrentDocument(), + '###FIELD_COLL###' => $this->addCurrentCollection(), '###ADDITIONAL_INPUTS###' => $this->addEncryptedCoreName(), '###FACETS_MENU###' => $this->addFacetsMenu() ); @@ -394,13 +418,13 @@ class tx_dlf_search extends tx_dlf_plugin { // Add filter query for in-collection searching. if ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all') { - $list = t3lib_div::makeInstance('tx_dlf_list'); + if (!empty($this->piVars['collection']) && t3lib_div::testInt($this->piVars['collection'])) { - if (!empty($list->metadata['options']['source']) && $list->metadata['options']['source'] == 'collection') { + $index_name = tx_dlf_helper::getIndexName($this->piVars['collection'], 'tx_dlf_collections', $this->conf['pages']); - $params['fq'][] = $list->metadata['options']['params']['fq'][0]; + $params['fq'][] = 'collection_faceting:"'.$index_name.'"'; - $label .= printf($this->pi_getLL('in', '', TRUE), $list->metadata['label']); + $label .= printf($this->pi_getLL('in', '', TRUE), tx_dlf_helper::translate($index_name, 'tx_dlf_collections', $this->conf['pages'])); } diff --git a/dlf/plugins/search/template.tmpl b/dlf/plugins/search/template.tmpl index ca680b06..e7215ddf 100644 --- a/dlf/plugins/search/template.tmpl +++ b/dlf/plugins/search/template.tmpl @@ -4,6 +4,7 @@ ###FIELD_DOC### + ###FIELD_COLL### ###ADDITIONAL_INPUTS###
###FACETS_MENU###