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 ...@@ -42,13 +42,16 @@ class Search extends AbstractHelper
/** /**
* Support function to display spelling suggestions. * 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 * @return string
*/ */
public function renderSpellingSuggestions($msg) public function renderSpellingSuggestions($msg, $results, $view)
{ {
$spellingSuggestions = $this->view->results->getSpellingSuggestions(); $spellingSuggestions = $results->getSpellingSuggestions();
if (empty($spellingSuggestions)) { if (empty($spellingSuggestions)) {
return ''; return '';
} }
...@@ -56,22 +59,22 @@ class Search extends AbstractHelper ...@@ -56,22 +59,22 @@ class Search extends AbstractHelper
$html = '<div class="corrections">'; $html = '<div class="corrections">';
$html .= $msg; $html .= $msg;
foreach ($spellingSuggestions as $term => $details) { foreach ($spellingSuggestions as $term => $details) {
$html .= '<br/>' . $this->view->escapeHtml($term) . ' &raquo; '; $html .= '<br/>' . $view->escapeHtml($term) . ' &raquo; ';
$i = 0; $i = 0;
foreach ($details['suggestions'] as $word => $data) { foreach ($details['suggestions'] as $word => $data) {
if ($i++ > 0) { if ($i++ > 0) {
$html .= ', '; $html .= ', ';
} }
$html .= '<a href="' $html .= '<a href="'
. $this->view->results->getUrlQuery() . $view->results->getUrlQuery()
->replaceTerm($term, $data['new_term']) ->replaceTerm($term, $data['new_term'])
. '">' . $this->view->escapeHtml($word) . '</a>'; . '">' . $view->escapeHtml($word) . '</a>';
if (isset($data['expand_term']) && !empty($data['expand_term'])) { if (isset($data['expand_term']) && !empty($data['expand_term'])) {
$html .= '<a href="' $html .= '<a href="'
. $this->view->results->getUrlQuery() . $results->getUrlQuery()
->replaceTerm($term, $data['expand_term']) ->replaceTerm($term, $data['expand_term'])
. '"><img src="' . $this->view->imageLink('silk/expand.png') . '"><img src="' . $view->imageLink('silk/expand.png')
. '" alt="' . $this->view->transEsc('spell_expand_alt') . '" alt="' . $view->transEsc('spell_expand_alt')
. '"/></a>'; . '"/></a>';
} }
} }
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<? if ($qtime = $this->results->getQuerySpeed()): ?> <? if ($qtime = $this->results->getQuerySpeed()): ?>
<?=$this->transEsc('query time')?>: <?=$this->escapeHtml(round($qtime, 2))?>s <?=$this->transEsc('query time')?>: <?=$this->escapeHtml(round($qtime, 2))?>s
<? endif; ?> <? endif; ?>
<?=$this->search()->renderSpellingSuggestions('<strong>' . $this->transEsc('spell_suggest') . '</strong>:'); ?> <?=$this->search()->renderSpellingSuggestions('<strong>' . $this->transEsc('spell_suggest') . '</strong>:', $this->results, $this); ?>
<? else: ?> <? else: ?>
<h3><?=$this->transEsc('nohit_heading')?></h3> <h3><?=$this->transEsc('nohit_heading')?></h3>
<? endif; ?> <? endif; ?>
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
<? if (isset($this->parseError)): ?> <? if (isset($this->parseError)): ?>
<p class="error"><?=$this->transEsc('nohit_parse_error')?></p> <p class="error"><?=$this->transEsc('nohit_parse_error')?></p>
<? endif; ?> <? 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): ?> <? foreach ($this->results->getRecommendations('top') as $current): ?>
<?=$this->recommend($current)?> <?=$this->recommend($current)?>
<? endforeach; ?> <? 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