The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 384a582e authored by Demian Katz's avatar Demian Katz
Browse files

Less "magic" in the renderSpellingSuggestions routine.

parent 0fbb78f8
No related merge requests found
......@@ -42,13 +42,16 @@ class Search extends AbstractHelper
/**
* Support function to display spelling suggestions.
*
* @param string $msg HTML to display at the top of the spelling section.
* @param string $msg HTML to display at the top of
* the spelling section.
* @param \VuFind\Search\Base\Results $results Results object
* @param \Zend\View\Renderer\PhpRenderer $view View renderer object
*
* @return string
*/
public function renderSpellingSuggestions($msg)
public function renderSpellingSuggestions($msg, $results, $view)
{
$spellingSuggestions = $this->view->results->getSpellingSuggestions();
$spellingSuggestions = $results->getSpellingSuggestions();
if (empty($spellingSuggestions)) {
return '';
}
......@@ -56,22 +59,22 @@ class Search extends AbstractHelper
$html = '<div class="corrections">';
$html .= $msg;
foreach ($spellingSuggestions as $term => $details) {
$html .= '<br/>' . $this->view->escapeHtml($term) . ' &raquo; ';
$html .= '<br/>' . $view->escapeHtml($term) . ' &raquo; ';
$i = 0;
foreach ($details['suggestions'] as $word => $data) {
if ($i++ > 0) {
$html .= ', ';
}
$html .= '<a href="'
. $this->view->results->getUrlQuery()
. $view->results->getUrlQuery()
->replaceTerm($term, $data['new_term'])
. '">' . $this->view->escapeHtml($word) . '</a>';
. '">' . $view->escapeHtml($word) . '</a>';
if (isset($data['expand_term']) && !empty($data['expand_term'])) {
$html .= '<a href="'
. $this->view->results->getUrlQuery()
. $results->getUrlQuery()
->replaceTerm($term, $data['expand_term'])
. '"><img src="' . $this->view->imageLink('silk/expand.png')
. '" alt="' . $this->view->transEsc('spell_expand_alt')
. '"><img src="' . $view->imageLink('silk/expand.png')
. '" alt="' . $view->transEsc('spell_expand_alt')
. '"/></a>';
}
}
......
......@@ -57,7 +57,7 @@
<? if ($qtime = $this->results->getQuerySpeed()): ?>
<?=$this->transEsc('query time')?>: <?=$this->escapeHtml(round($qtime, 2))?>s
<? endif; ?>
<?=$this->search()->renderSpellingSuggestions('<strong>' . $this->transEsc('spell_suggest') . '</strong>:'); ?>
<?=$this->search()->renderSpellingSuggestions('<strong>' . $this->transEsc('spell_suggest') . '</strong>:', $this->results, $this); ?>
<? else: ?>
<h3><?=$this->transEsc('nohit_heading')?></h3>
<? endif; ?>
......@@ -85,7 +85,7 @@
<? if (isset($this->parseError)): ?>
<p class="error"><?=$this->transEsc('nohit_parse_error')?></p>
<? endif; ?>
<?=$this->search()->renderSpellingSuggestions($this->transEsc('nohit_spelling') . ':'); ?>
<?=$this->search()->renderSpellingSuggestions($this->transEsc('nohit_spelling') . ':', $this->results, $this); ?>
<? foreach ($this->results->getRecommendations('top') as $current): ?>
<?=$this->recommend($current)?>
<? endforeach; ?>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment