Example #1
0
 /**
  * Represent the current search results as a feed.
  *
  * @param \VuFind\Search\Base\Results $results     Search results to convert to
  * feed
  * @param string                      $currentPath Base path to display in feed
  * (leave null to load dynamically using currentpath view helper)
  *
  * @return Feed
  */
 public function __invoke($results, $currentPath = null)
 {
     $this->registerExtension();
     // Determine base URL if not already provided:
     if (is_null($currentPath)) {
         $currentPath = $this->getView()->plugin('currentpath')->__invoke();
     }
     $serverUrl = $this->getView()->plugin('serverurl');
     $baseUrl = $serverUrl($currentPath);
     // Create the parent feed
     $feed = new Feed();
     $feed->setTitle($this->translate('Results for') . ' ' . $results->getParams()->getDisplayQuery());
     $feed->setLink($baseUrl . $results->getUrlQuery()->setViewParam(null, false));
     $feed->setFeedLink($baseUrl . $results->getUrlQuery()->getParams(false), $results->getParams()->getView());
     $feed->setDescription($this->translate('Showing') . ' ' . $results->getStartRecord() . '-' . $results->getEndRecord() . ' ' . $this->translate('of') . ' ' . $results->getResultTotal());
     $params = $results->getParams();
     // add atom links for easier paging
     $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage(1, false), 'first', $params->getView());
     if ($params->getPage() > 1) {
         $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() - 1, false), 'previous', $params->getView());
     }
     $lastPage = ceil($results->getResultTotal() / $params->getLimit());
     if ($params->getPage() < $lastPage) {
         $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() + 1, false), 'next', $params->getView());
     }
     $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($lastPage, false), 'last', $params->getView());
     // add opensearch fields
     $feed->setOpensearchTotalResults($results->getResultTotal());
     $feed->setOpensearchItemsPerPage($params->getLimit());
     $feed->setOpensearchStartIndex($results->getStartRecord() - 1);
     $feed->setOpensearchSearchTerms($params->getQuery()->getString());
     $records = $results->getResults();
     foreach ($records as $current) {
         $this->addEntry($feed, $current);
     }
     return $feed;
 }