From c89a8746c6ef62f8d28a483402d05427ea2eb1e4 Mon Sep 17 00:00:00 2001 From: Brandon Uhlman <brandon.uhlman@novascotia.ca> Date: Thu, 18 Jun 2015 14:53:12 -0400 Subject: [PATCH] Fix next/prev scrolling for author facet searches When running a keyword search, then choosing an author hyperlink from the results to run an author facet search, the next/previous links in the individual results would be based on the initial keyword search, not the facet search. This was for two reasons: - the ResultScroller was not active in the AuthorController, which handles author facet searches - the ResultScroller retrieves the current search from the session to create the scrolling links, and author facet searches were configured to not be saved in the session Correct these two issues in AuthorController, but only if next_prev_navigation is enabled. Because AuthorController also handles SolrAuthorFacet searches (searches that produce a list of authors, not a list of titles by a specific author) and those results cannot be iterated through by a ResultScroller, we also have to make an additional fix in the ResultScroller plugin to handle the case where SolrAuthorFacet result is passed to create the ResultScroller, and prevent it from being instantiated. --- .../VuFind/Controller/AuthorController.php | 21 ++++++++++++++++++- .../Controller/Plugin/ResultScroller.php | 5 ++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/module/VuFind/src/VuFind/Controller/AuthorController.php b/module/VuFind/src/VuFind/Controller/AuthorController.php index a64233c56d0..ef4a66657a5 100644 --- a/module/VuFind/src/VuFind/Controller/AuthorController.php +++ b/module/VuFind/src/VuFind/Controller/AuthorController.php @@ -46,7 +46,14 @@ class AuthorController extends AbstractSearch public function resultsAction() { $this->searchClassId = 'SolrAuthor'; - $this->saveToHistory = false; + + // Save author searches if next_prev_navigation is enabled - otherwise + // there are wacky results when trying to page through results (the + // next/prev links only appear for records which were included in the + // results for the previous keyword search, and the next/prev links will + // iterate you through that search). + $this->saveToHistory = $this->resultScrollerActive(); + return parent::resultsAction(); } @@ -78,5 +85,17 @@ class AuthorController extends AbstractSearch } return $this->createViewModel(); } + + /** + * Is the result scroller active? + * + * @return bool + */ + protected function resultScrollerActive() + { + $config = $this->getServiceLocator()->get('VuFind\Config')->get('config'); + return (isset($config->Record->next_prev_navigation) + && $config->Record->next_prev_navigation); + } } diff --git a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php index d9f9d23681e..c0cb13990fd 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php @@ -98,7 +98,7 @@ class ResultScroller extends AbstractPlugin unset($this->data->prevIds); unset($this->data->nextIds); - return true; + return (bool)$this->data->currIds; } /** @@ -393,6 +393,9 @@ class ResultScroller extends AbstractPlugin $retVal = []; foreach ($searchObject->getResults() as $record) { + if (!($record instanceof \VuFind\RecordDriver\AbstractBase)) { + return false; + } $retVal[] = $record->getResourceSource() . '|' . $record->getUniqueId(); } return $retVal; -- GitLab