Fix Bug #801953: Group associated documents/hits

This commit is contained in:
Sebastian Meyer 2012-03-15 16:57:06 +01:00
commit 6556e9e4ad
8 changed files with 269 additions and 73 deletions

View File

@ -165,7 +165,7 @@ class tx_dlf_list implements t3lib_Singleton {
}
/**
* This empties the current list
* This clears the current list
*
* @access public
*

View File

@ -112,7 +112,10 @@ class tx_dlf_solr {
$solr = t3lib_div::makeInstance('Apache_Solr_Service', $host, $port, $path);
// Check if connection is established.
if ($solr->ping()) {
if ($solr->ping() !== FALSE) {
// Do not collapse single value arrays.
$solr->setCollapseSingleValueArrays = FALSE;
return $solr;

View File

@ -250,88 +250,102 @@ class tx_dlf_collection extends tx_dlf_plugin {
*/
protected function showSingleCollection($id) {
$orderBy = 'tx_dlf_documents.title_sorting';
if (!empty($this->piVars['order'])) {
switch ($this->piVars['order']) {
case 'title':
case 'author':
case 'place':
case 'year':
$orderBy = 'tx_dlf_documents.'.$this->piVars['order'].'_sorting ASC';
break;
case '-title':
case '-author':
case '-place':
case '-year':
$orderBy = 'tx_dlf_documents.'.substr($this->piVars['order'], 1).'_sorting DESC';
break;
}
}
// Get all documents in collection.
$result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
'tx_dlf_collections.label AS collLabel,tx_dlf_collections.description AS collDesc,tx_dlf_documents.uid AS uid,tx_dlf_documents.title AS title,tx_dlf_documents.volume AS volume,tx_dlf_documents.author AS author,tx_dlf_documents.place AS place,tx_dlf_documents.year AS year,tx_dlf_documents.structure AS type',
'tx_dlf_collections.label AS collLabel,tx_dlf_collections.description AS collDesc,tx_dlf_documents.uid AS uid,tx_dlf_documents.title AS title,tx_dlf_documents.volume AS volume,tx_dlf_documents.volume_sorting AS volume_sorting,tx_dlf_documents.author AS author,tx_dlf_documents.place AS place,tx_dlf_documents.year AS year,tx_dlf_documents.structure AS type,tx_dlf_documents.partof AS partof',
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
'AND tx_dlf_documents.partof=0 AND tx_dlf_collections.uid='.$GLOBALS['TYPO3_DB']->fullQuoteStr($id, 'tx_dlf_collections').' AND tx_dlf_collections.pid='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->conf['pages'], 'tx_dlf_collections').tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'AND tx_dlf_collections.uid='.intval($id).' AND tx_dlf_collections.pid='.intval($this->conf['pages']).tx_dlf_helper::whereClause('tx_dlf_documents').tx_dlf_helper::whereClause('tx_dlf_collections'),
'',
$orderBy,
'tx_dlf_documents.title_sorting ASC',
''
);
$_list = array ();
$toplevel = array ();
// Process results.
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
if (empty($_metadata)) {
$_metadata = array (
'uid' => $id,
'label' => $resArray['collLabel'],
'description' => $this->pi_RTEcssText($resArray['collDesc']),
'options' => array (
'orderBy' => $this->piVars['order']
'source' => 'collection',
'select' => $id,
'order' => 'title'
)
);
}
$_list[] = array (
'uid' => $resArray['uid'],
'page' => 1,
'title' => array ($resArray['title']),
'volume' => array ($resArray['volume']),
'author' => array ($resArray['author']),
'year' => array ($resArray['year']),
'place' => array ($resArray['place']),
'type' => array (tx_dlf_helper::getIndexName($resArray['type'], 'tx_dlf_structures', $this->conf['pages'])),
'subparts' => array ()
);
// Split toplevel documents from volumes.
if ($resArray['partof'] == 0) {
$toplevel[$resArray['uid']] = array (
'uid' => $resArray['uid'],
'page' => 1,
'title' => array ($resArray['title']),
'volume' => array ($resArray['volume']),
'author' => array ($resArray['author']),
'year' => array ($resArray['year']),
'place' => array ($resArray['place']),
'type' => array (tx_dlf_helper::getIndexName($resArray['type'], 'tx_dlf_structures', $this->conf['pages'])),
'subparts' => array ()
);
} else {
$subparts[$resArray['partof']][$resArray['volume_sorting']] = array (
'uid' => $resArray['uid'],
'page' => 1,
'title' => array ($resArray['title']),
'volume' => array ($resArray['volume']),
'author' => array ($resArray['author']),
'year' => array ($resArray['year']),
'place' => array ($resArray['place']),
'type' => array (tx_dlf_helper::getIndexName($resArray['type'], 'tx_dlf_structures', $this->conf['pages']))
);
}
}
// Add volumes to the corresponding toplevel documents.
foreach ($subparts as $partof => $parts) {
if (!empty($toplevel[$partof])) {
ksort($parts);
$toplevel[$partof]['subparts'] = array_values($parts);
}
}
// Save list of documents.
$list = t3lib_div::makeInstance('tx_dlf_list');
$list->reset();
$list->add($_list);
$list->add(array_values($toplevel));
$list->metadata = $_metadata;
$list->save();
// Clean output buffer.
t3lib_div::cleanOutputBuffers();
// Send headers.
header('Location: '.t3lib_div::locationHeaderUrl($this->pi_getPageLink($this->conf['targetPid'])));
// Flush output buffer and end script processing.
ob_end_flush();
exit;
}

View File

@ -98,6 +98,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
$i = 0;
// Add links to pages.
while ($i < $maxPages) {
if ($i < 3 || ($i > $this->piVars['pointer'] - 3 && $i < $this->piVars['pointer'] + 3) || $i > $maxPages - 4) {
@ -126,6 +127,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
}
// Add link to next page.
if ($this->piVars['pointer'] < $maxPages - 1) {
$output .= $this->pi_linkTP_keepPIvars($this->pi_getLL('nextPage', '&gt;'), array ('pointer' => $this->piVars['pointer'] + 1), TRUE);
@ -219,27 +221,100 @@ class tx_dlf_listview extends tx_dlf_plugin {
}
// if (!empty($this->list->elements[$number]['subparts'])) {
//
// foreach ($this->list->elements[$number]['subparts'] as $_subpart) {
//
// $subpart = $this->getSubEntry($_subpart, $template);
if (!empty($this->list->elements[$number]['subparts'])) {
$subpart = $this->getSubEntries($number, $template);
}
return $this->cObj->substituteMarkerArray($this->cObj->substituteSubpart($template['entry'], '###SUBTEMPLATE###', $subpart, TRUE), $markerArray);
}
/**
* Renders one sub-entry of the list
* Renders all sub-entries of one entry
*
* @access protected
*
* @param integer $number: The number of the entry
* @param string $template: Parsed template subpart
*
* @return string The rendered entry ready for output
* @return string The rendered entries ready for output
*/
protected function getSubEntry($number, $template) {
protected function getSubEntries($number, $template) {
$content = '';
foreach ($this->list->elements[$number]['subparts'] as $subpart) {
$markerArray['###SUBMETADATA###'] = '';
foreach ($this->metadata as $_index_name => $_wrap) {
$hasValue = FALSE;
if (is_array($subpart[$_index_name]) && !empty($this->labels[$_index_name])) {
$fieldwrap = $this->parseTS($_wrap);
$field = $this->cObj->stdWrap(htmlspecialchars($this->labels[$_index_name]), $fieldwrap['key.']);
foreach ($subpart[$_index_name] as $_value) {
// Link title to pageview.
if ($_index_name == 'title') {
// Get title of parent document if needed.
if (empty($_value) && $this->conf['getTitle']) {
$_value = '['.tx_dlf_document::getTitle($subpart['uid'], TRUE).']';
}
// Set fake title if still not present.
if (empty($_value)) {
$_value = $this->pi_getLL('noTitle');
}
$_value = $this->pi_linkTP(htmlspecialchars($_value), array ($this->prefixId => array ('id' => $subpart['uid'], 'page' => $subpart['page'], 'pointer' => $this->piVars['pointer'])), TRUE, $this->conf['targetPid']);
} elseif ($_index_name == 'type' && !empty($_value)) {
$_value = $this->pi_getLL($_value, tx_dlf_helper::translate($_value, 'tx_dlf_structures', $this->conf['pages']), FALSE);
} elseif (!empty($_value)) {
$_value = htmlspecialchars($_value);
}
if (!empty($_value)) {
$field .= $this->cObj->stdWrap($_value, $fieldwrap['value.']);
$hasValue = TRUE;
}
}
if ($hasValue) {
$markerArray['###SUBMETADATA###'] .= $this->cObj->stdWrap($field, $fieldwrap['all.']);
}
}
}
$content .= $this->cObj->substituteMarkerArray($template['subentry'], $markerArray);
}
return $this->cObj->substituteSubpart($this->cObj->getSubpart($this->template, '###SUBTEMPLATE###'), '###SUBENTRY###', $content, TRUE);
}
@ -314,6 +389,8 @@ class tx_dlf_listview extends tx_dlf_plugin {
$subpartArray['entry'] = $this->cObj->getSubpart($this->template, '###ENTRY###');
$subpartArray['subentry'] = $this->cObj->getSubpart($this->template, '###SUBENTRY###');
// Set some variable defaults.
if (!empty($this->piVars['pointer']) && (($this->piVars['pointer'] * $this->conf['limit']) + 1) <= $this->list->count) {

View File

@ -11,8 +11,6 @@
</dl>
<div class="floatclear"></div>
<!-- ###SUBTEMPLATE### -->
<span class="tx-dlf-morevolumes">weitere Bände</span>
<span class="tx-dlf-hidevolumes">Bände ausblenden</span>
<ol class="tx-dlf-volume">
<!-- ###SUBENTRY### -->
<li>

View File

@ -85,47 +85,135 @@ class tx_dlf_search extends tx_dlf_plugin {
} else {
// Get Solr instance...
$solr = tx_dlf_solr::solrConnect($this->conf['solrcore']);
// ...and perform search.
$query = $solr->search($this->piVars['query'], 0, $this->conf['limit'], array ());
$numHits = count($query->response->docs);
$_list = array ();
// Set metadata for search.
$_metadata = array (
'uid' => 0,
'label' => sprintf($this->pi_getLL('searchfor', ''), $this->piVars['query']),
'description' => '',
'options' => array ()
'description' => sprintf($this->pi_getLL('hits', ''), $numHits),
'options' => array (
'source' => 'search',
'select' => $this->piVars['query'],
'order' => 'relevance'
)
);
$toplevel = array ();
$check = array ();
// Process results.
foreach ($query->response->docs as $doc) {
$_list[] = array (
'uid' => $doc->uid,
'page' => $doc->page,
'title' => (is_array($doc->title) ? $doc->title : array ($doc->title)),
'volume' => (is_array($doc->volume) ? $doc->volume : array ($doc->volume)),
'author' => (is_array($doc->author) ? $doc->author : array ($doc->author)),
'year' => (is_array($doc->year) ? $doc->year : array ($doc->year)),
'place' => (is_array($doc->place) ? $doc->place : array ($doc->place)),
'type' => (is_array($doc->type) ? $doc->type : array ($doc->type)),
'subparts' => array ()
);
// Split toplevel documents from subparts.
if ($doc->toplevel == 1) {
$toplevel[$doc->uid] = array (
'uid' => $doc->uid,
'page' => $doc->page,
'title' => (is_array($doc->title) ? $doc->title : array ($doc->title)),
'volume' => (is_array($doc->volume) ? $doc->volume : array ($doc->volume)),
'author' => (is_array($doc->author) ? $doc->author : array ($doc->author)),
'year' => (is_array($doc->year) ? $doc->year : array ($doc->year)),
'place' => (is_array($doc->place) ? $doc->place : array ($doc->place)),
'type' => (is_array($doc->type) ? $doc->type : array ($doc->type)),
'subparts' => (!empty($toplevel[$doc->uid]['subparts']) ? $toplevel[$doc->uid]['subparts'] : array ())
);
} else {
$toplevel[$doc->uid]['subparts'][] = array (
'uid' => $doc->uid,
'page' => $doc->page,
'title' => (is_array($doc->title) ? $doc->title : array ($doc->title)),
'volume' => (is_array($doc->volume) ? $doc->volume : array ($doc->volume)),
'author' => (is_array($doc->author) ? $doc->author : array ($doc->author)),
'year' => (is_array($doc->year) ? $doc->year : array ($doc->year)),
'place' => (is_array($doc->place) ? $doc->place : array ($doc->place)),
'type' => (is_array($doc->type) ? $doc->type : array ($doc->type))
);
if (!in_array($doc->uid, $check)) {
$check[] = $doc->uid;
}
}
}
// Check if the toplevel documents have metadata.
foreach ($check as $_check) {
if (empty($toplevel[$_check]['uid'])) {
// Get information for toplevel document.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.uid AS uid,tx_dlf_documents.title AS title,tx_dlf_documents.volume AS volume,tx_dlf_documents.author AS author,tx_dlf_documents.place AS place,tx_dlf_documents.year AS year,tx_dlf_documents.structure AS type',
'tx_dlf_documents',
'tx_dlf_documents.uid='.intval($_check).tx_dlf_helper::whereClause('tx_dlf_documents'),
'',
'',
'1'
);
// Process results.
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
$toplevel[$_check] = array (
'uid' => $resArray['uid'],
'page' => 1,
'title' => array ($resArray['title']),
'volume' => array ($resArray['volume']),
'author' => array ($resArray['author']),
'year' => array ($resArray['year']),
'place' => array ($resArray['place']),
'type' => array (tx_dlf_helper::getIndexName($resArray['type'], 'tx_dlf_structures', $this->conf['pages'])),
'subparts' => $toplevel[$_check]['subparts']
);
} else {
// Clear entry if there is no (accessible) toplevel document.
unset ($toplevel[$_check]);
}
}
}
// Save list of documents.
$list = t3lib_div::makeInstance('tx_dlf_list');
$list->reset();
$list->add($_list);
$list->add(array_values($toplevel));
$list->metadata = $_metadata;
$list->save();
// Clean output buffer.
t3lib_div::cleanOutputBuffers();
// Send headers.
header('Location: '.t3lib_div::locationHeaderUrl($this->pi_getPageLink($this->conf['targetPid'])));
// Flush output buffer and end script processing.
ob_end_flush();
exit;
}

View File

@ -11,6 +11,20 @@
</TCEforms>
<type>array</type>
<el>
<pages>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:lang/locallang_general.xml:LGL.startingpoint</label>
<config>
<type>group</type>
<internal_type>db</internal_type>
<allowed>pages</allowed>
<size>1</size>
<maxitems>1</maxitems>
<minitems>1</minitems>
</config>
</TCEforms>
</pages>
<solrcore>
<TCEforms>
<exclude>1</exclude>

View File

@ -14,6 +14,7 @@
<label index="label.query">Search for:</label>
<label index="label.submit">Search</label>
<label index="searchfor">Search for: "%s"</label>
<label index="hits">%d hits found.</label>
</languageKey>
<languageKey index="de" type="array">
<label index="tt_content.pi_flexform.sheet_general">Einstellungen</label>
@ -24,6 +25,7 @@
<label index="label.query">Suchen nach:</label>
<label index="label.submit">Suchen</label>
<label index="searchfor">Suche nach: "%s"</label>
<label index="hits">Die Suche ergab %d Treffer.</label>
</languageKey>
</data>
</T3locallang>