From 3a1cf8ac2a2358f467d3a389ccc5cf510b82cd97 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 8 Jul 2014 14:25:43 -0400 Subject: [PATCH] Implemented "hide_if_empty" for combined results. --- config/vufind/combined.ini | 3 +++ .../VuFind/Controller/CombinedController.php | 18 ++++++++++++++---- .../templates/combined/results-ajax.phtml | 2 +- .../blueprint/templates/combined/results.phtml | 1 + .../templates/combined/results-ajax.phtml | 2 +- .../bootstrap/templates/combined/results.phtml | 1 + .../templates/combined/results-ajax.phtml | 2 +- .../templates/combined/results.phtml | 1 + .../templates/combined/results-ajax.phtml | 3 ++- .../templates/combined/results.phtml | 1 + 10 files changed, 26 insertions(+), 8 deletions(-) diff --git a/config/vufind/combined.ini b/config/vufind/combined.ini index 17bdc9a1ec7..24823d7999c 100644 --- a/config/vufind/combined.ini +++ b/config/vufind/combined.ini @@ -10,6 +10,9 @@ ; combined search in a simplified manner. ; ajax = If true, these results will load via AJAX; otherwise, they will load ; inline (default = false) +; hide_if_empty = If true, this section will be completely suppressed from +; display when an empty result set is returned. Otherwise, +; it will display the standard "no results" message. ; limit = The maximum number of search results to show in this column; note ; that this must be a legal limit value for the chosen search backend. ; (Setting legal limit values may require changing limit_options in diff --git a/module/VuFind/src/VuFind/Controller/CombinedController.php b/module/VuFind/src/VuFind/Controller/CombinedController.php index 354d101b936..4e9cc2188ee 100644 --- a/module/VuFind/src/VuFind/Controller/CombinedController.php +++ b/module/VuFind/src/VuFind/Controller/CombinedController.php @@ -95,10 +95,20 @@ class CombinedController extends AbstractSearch $headers->addHeaderLine('Content-type', 'text/html'); $headers->addHeaderLine('Cache-Control', 'no-cache, must-revalidate'); $headers->addHeaderLine('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); - $html = $this->getViewRenderer()->render( - 'combined/results-list.phtml', - array('searchClassId' => $searchClassId, 'currentSearch' => $settings) - ); + + // Should we suppress content due to emptiness? + if (isset($settings['hide_if_empty']) && $settings['hide_if_empty'] + && $settings['view']->results->getResultTotal() == 0 + ) { + $html = ''; + } else { + $html = $this->getViewRenderer()->render( + 'combined/results-list.phtml', + array( + 'searchClassId' => $searchClassId, 'currentSearch' => $settings + ) + ); + } $response->setContent($html); return $response; } diff --git a/themes/blueprint/templates/combined/results-ajax.phtml b/themes/blueprint/templates/combined/results-ajax.phtml index 96e9110de9d..d717669d166 100644 --- a/themes/blueprint/templates/combined/results-ajax.phtml +++ b/themes/blueprint/templates/combined/results-ajax.phtml @@ -7,7 +7,7 @@ // Set up Javascript for use below: $loadJs = 'var url = path + "/Combined/Result?id=' . urlencode($searchClassId) . '&lookfor=' . urlencode($lookfor) . '";' - . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url);"; + . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url, '', function(responseText) { if (responseText.length == 0) $('#combined_" . $this->escapeHtml($searchClassId) . "').hide(); });"; ?> <h2><?=$this->transEsc($currentSearch['label'])?></h2> <p><?=$this->transEsc("Loading")?>... <img src="<?=$this->imageLink('ajax_loading.gif')?>" /></p> diff --git a/themes/blueprint/templates/combined/results.phtml b/themes/blueprint/templates/combined/results.phtml index a80cff680f3..80991ee682c 100644 --- a/themes/blueprint/templates/combined/results.phtml +++ b/themes/blueprint/templates/combined/results.phtml @@ -48,6 +48,7 @@ <? endif; ?> <?=$this->flashmessages()?> <? foreach ($this->combinedResults as $searchClassId => $currentSearch): ?> + <? if ((!isset($currentSearch['ajax']) || !$currentSearch['ajax']) && isset($currentSearch['hide_if_empty']) && $currentSearch['hide_if_empty'] && $currentSearch['view']->results->getResultTotal() == 0) { continue; } ?> <div class="combinedResult" id="combined_<?=$this->escapeHtml($searchClassId)?>"> <? if (isset($currentSearch['ajax']) && $currentSearch['ajax']): ?> <?=$this->render('combined/results-ajax.phtml', array('searchClassId' => $searchClassId, 'currentSearch' => $currentSearch))?> diff --git a/themes/bootstrap/templates/combined/results-ajax.phtml b/themes/bootstrap/templates/combined/results-ajax.phtml index 8cad1649579..34876cae822 100644 --- a/themes/bootstrap/templates/combined/results-ajax.phtml +++ b/themes/bootstrap/templates/combined/results-ajax.phtml @@ -7,7 +7,7 @@ // Set up Javascript for use below: $loadJs = 'var url = path + "/Combined/Result?id=' . urlencode($searchClassId) . '&lookfor=' . urlencode($lookfor) . '";' - . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url);"; + . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url, '', function(responseText) { if (responseText.length == 0) $('#combined_" . $this->escapeHtml($searchClassId) . "').hide(); });"; ?> <h2><?=$this->transEsc($currentSearch['label'])?></h2> <p><i class="icon-spinner icon-spin"></i> <?=$this->transEsc("Loading")?>...</p> diff --git a/themes/bootstrap/templates/combined/results.phtml b/themes/bootstrap/templates/combined/results.phtml index 3f55920b07a..3750adb71e0 100644 --- a/themes/bootstrap/templates/combined/results.phtml +++ b/themes/bootstrap/templates/combined/results.phtml @@ -57,6 +57,7 @@ <div class="row-fluid"> <? $columns = count($this->combinedResults); ?> <? foreach ($this->combinedResults as $searchClassId => $currentSearch): ?> + <? if ((!isset($currentSearch['ajax']) || !$currentSearch['ajax']) && isset($currentSearch['hide_if_empty']) && $currentSearch['hide_if_empty'] && $currentSearch['view']->results->getResultTotal() == 0) { continue; } ?> <div class="span<?=floor(12/$columns)?> combined-list" id="combined_<?=$this->escapeHtml($searchClassId)?>"> <? if (isset($currentSearch['ajax']) && $currentSearch['ajax']): ?> <?=$this->render('combined/results-ajax.phtml', array('searchClassId' => $searchClassId, 'currentSearch' => $currentSearch))?> diff --git a/themes/bootstrap3/templates/combined/results-ajax.phtml b/themes/bootstrap3/templates/combined/results-ajax.phtml index 339436f147e..455f9c07555 100644 --- a/themes/bootstrap3/templates/combined/results-ajax.phtml +++ b/themes/bootstrap3/templates/combined/results-ajax.phtml @@ -7,7 +7,7 @@ // Set up Javascript for use below: $loadJs = 'var url = path + "/Combined/Result?id=' . urlencode($searchClassId) . '&lookfor=' . urlencode($lookfor) . '";' - . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url);"; + . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url, '', function(responseText) { if (responseText.length == 0) $('#combined_" . $this->escapeHtml($searchClassId) . "').hide(); });"; ?> <h2><?=$this->transEsc($currentSearch['label'])?></h2> <p><i class="fa fa-spinner icon-spin"></i> <?=$this->transEsc("Loading")?>...</p> diff --git a/themes/bootstrap3/templates/combined/results.phtml b/themes/bootstrap3/templates/combined/results.phtml index 9da48811bad..a652ec14d87 100644 --- a/themes/bootstrap3/templates/combined/results.phtml +++ b/themes/bootstrap3/templates/combined/results.phtml @@ -57,6 +57,7 @@ <div class="row"> <? $columns = count($this->combinedResults); ?> <? foreach ($this->combinedResults as $searchClassId => $currentSearch): ?> + <? if ((!isset($currentSearch['ajax']) || !$currentSearch['ajax']) && isset($currentSearch['hide_if_empty']) && $currentSearch['hide_if_empty'] && $currentSearch['view']->results->getResultTotal() == 0) { continue; } ?> <div class="col-sm-<?=floor(12/$columns)?> combined-list" id="combined_<?=$this->escapeHtml($searchClassId)?>"> <? if (isset($currentSearch['ajax']) && $currentSearch['ajax']): ?> <?=$this->render('combined/results-ajax.phtml', array('searchClassId' => $searchClassId, 'currentSearch' => $currentSearch))?> diff --git a/themes/jquerymobile/templates/combined/results-ajax.phtml b/themes/jquerymobile/templates/combined/results-ajax.phtml index 2672a66a126..eaf0b46e084 100644 --- a/themes/jquerymobile/templates/combined/results-ajax.phtml +++ b/themes/jquerymobile/templates/combined/results-ajax.phtml @@ -7,7 +7,8 @@ // Set up Javascript for use below: $loadJs = 'var url = path + "/Combined/Result?id=' . urlencode($searchClassId) . '&lookfor=' . urlencode($lookfor) . '";' - . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url, function() {" + . "\$('#combined_" . $this->escapeHtml($searchClassId) . "').load(url, '', function(responseText) {" + . "if (responseText.length == 0) $('#combined_" . $this->escapeHtml($searchClassId) . "').hide();" . "$('.combinedButton').button(); });"; ?> <h2><?=$this->transEsc($currentSearch['label'])?></h2> diff --git a/themes/jquerymobile/templates/combined/results.phtml b/themes/jquerymobile/templates/combined/results.phtml index 6141a380a84..3bd8b746e26 100644 --- a/themes/jquerymobile/templates/combined/results.phtml +++ b/themes/jquerymobile/templates/combined/results.phtml @@ -12,6 +12,7 @@ <div data-role="content"> <?=$this->flashmessages()?> <? foreach ($this->combinedResults as $searchClassId => $currentSearch): ?> + <? if ((!isset($currentSearch['ajax']) || !$currentSearch['ajax']) && isset($currentSearch['hide_if_empty']) && $currentSearch['hide_if_empty'] && $currentSearch['view']->results->getResultTotal() == 0) { continue; } ?> <div class="combinedResult" id="combined_<?=$this->escapeHtml($searchClassId)?>"> <? if (isset($currentSearch['ajax']) && $currentSearch['ajax']): ?> <?=$this->render('combined/results-ajax.phtml', array('searchClassId' => $searchClassId, 'currentSearch' => $currentSearch))?> -- GitLab