Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display side recommendations with combined search #3135

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/vufind/combined.ini
Expand Up @@ -28,6 +28,11 @@
; specified recommendations will be loaded into the top
; area of the column. If set to false, recommendations
; will be suppressed (default).
; include_recommendations_side = If set to true, standard 'side' recommendations
; will be displayed in the sidebar column. If set to an array of
; recommendation settings (as per searches.ini), the specified recommendations
; will be loaded into the side column. If set to false, side recommendations
; will be suppressed (default).
; filter = One or more filters to apply to search results displayed in the column.
; Use multiple "filter[] = ..." lines if multiple filters are needed.
; hiddenFilter = One or more hidden filters to apply to search results displayed in
Expand Down
29 changes: 21 additions & 8 deletions module/VuFind/src/VuFind/Controller/CombinedController.php
Expand Up @@ -225,6 +225,15 @@ public function resultsAction()
$settings = $this->serviceLocator->get(\VuFind\Config\PluginManager::class)
->get('config');

// Identify if any modules use include_recommendations_side
$anySideRecommendations = false;
foreach ($config as $subconfig) {
if ($subconfig['include_recommendations_side'] ?? false) {
$anySideRecommendations = true;
break;
}
}

// Build view model:
return $this->createViewModel(
[
Expand All @@ -237,6 +246,7 @@ public function resultsAction()
'supportsCart' => $supportsCart,
'supportsCartOptions' => $supportsCartOptions,
'showBulkOptions' => $settings->Site->showBulkOptions ?? false,
'anySideRecommendations' => $anySideRecommendations,
]
);
}
Expand Down Expand Up @@ -325,15 +335,18 @@ protected function adjustQueryForSettings($settings, $searchType = null)
// Override the search type:
$query->type = $searchType;

// Always leave noresults active (useful for 0-hit searches) and
// side inactive (no room to display) but display or hide top based
// on include_recommendations setting.
if ($settings['include_recommendations'] ?? false) {
$query->noRecommend = 'side';
if (is_array($settings['include_recommendations'])) {
$query->recommendOverride
= ['top' => $settings['include_recommendations']];
// Always leave noresults active (useful for 0-hit searches).
// Display or hide top based on include_recommendations setting.
// Display or hide top based on include_recommendations_side setting.
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
if (($settings['include_recommendations'] ?? false) || ($settings['include_recommendations_side'] ?? false)) {
$recommendOverride = [];
if (is_array($settings['include_recommendations'] ?? null)) {
$recommendOverride['top'] = $settings['include_recommendations'];
}
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
if (is_array($settings['include_recommendations_side'] ?? null)) {
$recommendOverride['side'] = $settings['include_recommendations_side'];
}
$query->recommendOverride = $recommendOverride;
} else {
$query->noRecommend = 'top,side';
}
Expand Down
1 change: 1 addition & 0 deletions module/VuFind/src/VuFind/Search/Combined/Options.php
Expand Up @@ -81,6 +81,7 @@ public function getRecommendationSettings($handler = null)
$recommend = [];
$config = $this->configLoader->get('combined');
foreach (['top', 'bottom'] as $location) {
// foreach (['top', 'bottom', 'side'] as $location) {
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
if (isset($config->RecommendationModules->$location)) {
$recommend[$location]
= $config->RecommendationModules->$location->toArray();
Expand Down
23 changes: 23 additions & 0 deletions themes/bootstrap3/templates/combined/results-list.phtml
Expand Up @@ -68,6 +68,29 @@
<?php foreach (($top = $results->getRecommendations('top')) as $current): ?>
<?=$this->recommend($current)?>
<?php endforeach; ?>
<?php foreach (($side = $results->getRecommendations('side')) as $current):
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
$recommendationClass = str_replace('\\', '_', $current::class);
$recommendationJs = <<<JS
function addRecommendation_$recommendationClass() {
const sidebar = document.getElementById('search-sidebar');
const recommendation = document.getElementById('recommendation__$recommendationClass');
sidebar.append(recommendation);
recommendation.style.display = 'inherit';
}

if (document.readyState != 'loading') {
addRecommendation_$recommendationClass();
}
else {
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
document.addEventListener('DOMContentLoaded', addRecommendation_$recommendationClass);
}
JS;
?>
<?=$this->inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $recommendationJs, 'SET')?>
<div id="recommendation__<?=$recommendationClass?>" style="display: none;">
<?=$this->recommend($current)?>
</div>
<?php endforeach; ?>
<?=
$this->context()->renderInContext(
'search/controls/showing.phtml',
Expand Down
16 changes: 15 additions & 1 deletion themes/bootstrap3/templates/combined/results.phtml
Expand Up @@ -73,7 +73,21 @@
'showBulkOptions' => $this->showBulkOptions,
];
?>
<?=$this->context($this)->renderInContext('combined/stack-' . $placement . '.phtml', $viewParams); ?>

<?php if ($anySideRecommendations ?? false): ?>
<div class="<?=$this->layoutClass('mainbody')?>">
<?=$this->context($this)->renderInContext('combined/stack-' . $placement . '.phtml', $viewParams); ?>
</div>

<div class="<?=$this->layoutClass('sidebar')?>" id="search-sidebar">
<?php /* foreach ($this->results->getRecommendations('side') as $index => $current): ?>
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
<?=$this->recommend($current, 'side', $index)?>
<?php endforeach; */ ?>
</div>
<?php else: ?>
<?=$this->context($this)->renderInContext('combined/stack-' . $placement . '.phtml', $viewParams); ?>
<?php endif; ?>

<?php $recs = $combinedResults->getRecommendations('bottom'); ?>
<?php if (!empty($recs)): ?>
<div>
Expand Down