예제 #1
0
 /**
  * Get a callback for setting up a search (or null if callback is unnecessary).
  *
  * @return mixed
  */
 protected function getSearchSetupCallback()
 {
     // Setup callback to attach listener if appropriate:
     $activeRecs = $this->getActiveRecommendationSettings();
     if (empty($activeRecs)) {
         return null;
     }
     $rManager = $this->getServiceLocator()->get('VuFind\\RecommendPluginManager');
     // Special case: override recommend settings through parameter (used by
     // combined search)
     if ($override = $this->params()->fromQuery('recommendOverride')) {
         return function ($runner, $p, $searchId) use($rManager, $override) {
             $listener = new RecommendListener($rManager, $searchId);
             $listener->setConfig($override);
             $listener->attach($runner->getEventManager()->getSharedManager());
         };
     }
     // Standard case: retrieve recommend settings from params object:
     return function ($runner, $params, $searchId) use($rManager, $activeRecs) {
         $listener = new RecommendListener($rManager, $searchId);
         $config = [];
         $rawConfig = $params->getOptions()->getRecommendationSettings($params->getSearchHandler());
         foreach ($rawConfig as $key => $value) {
             if (in_array($key, $activeRecs)) {
                 $config[$key] = $value;
             }
         }
         $listener->setConfig($config);
         $listener->attach($runner->getEventManager()->getSharedManager());
     };
 }
예제 #2
0
 /**
  * Send user's saved favorites from a particular list to the view
  *
  * @return mixed
  */
 public function mylistAction()
 {
     // Fail if lists are disabled:
     if (!$this->listsEnabled()) {
         throw new \Exception('Lists disabled');
     }
     // Check for "delete item" request; parameter may be in GET or POST depending
     // on calling context.
     $deleteId = $this->params()->fromPost('delete', $this->params()->fromQuery('delete'));
     if ($deleteId) {
         $deleteSource = $this->params()->fromPost('source', $this->params()->fromQuery('source', DEFAULT_SEARCH_BACKEND));
         // If the user already confirmed the operation, perform the delete now;
         // otherwise prompt for confirmation:
         $confirm = $this->params()->fromPost('confirm', $this->params()->fromQuery('confirm'));
         if ($confirm) {
             $success = $this->performDeleteFavorite($deleteId, $deleteSource);
             if ($success !== true) {
                 return $success;
             }
         } else {
             return $this->confirmDeleteFavorite($deleteId, $deleteSource);
         }
     }
     // If we got this far, we just need to display the favorites:
     try {
         $runner = $this->getServiceLocator()->get('VuFind\\SearchRunner');
         // We want to merge together GET, POST and route parameters to
         // initialize our search object:
         $request = $this->getRequest()->getQuery()->toArray() + $this->getRequest()->getPost()->toArray() + ['id' => $this->params()->fromRoute('id')];
         // Set up listener for recommendations:
         $rManager = $this->getServiceLocator()->get('VuFind\\RecommendPluginManager');
         $setupCallback = function ($runner, $params, $searchId) use($rManager) {
             $listener = new RecommendListener($rManager, $searchId);
             $listener->setConfig($params->getOptions()->getRecommendationSettings());
             $listener->attach($runner->getEventManager()->getSharedManager());
         };
         $results = $runner->run($request, 'Favorites', $setupCallback);
         return $this->createViewModel(['params' => $results->getParams(), 'results' => $results]);
     } catch (ListPermissionException $e) {
         if (!$this->getUser()) {
             return $this->forceLogin();
         }
         throw $e;
     }
 }
예제 #3
0
 /**
  * Retrieve side facets
  *
  * @return \Zend\Http\Response
  */
 public function getSideFacetsAjax()
 {
     $this->disableSessionWrites();
     // avoid session write timing bug
     // Send both GET and POST variables to search class:
     $request = $this->getRequest()->getQuery()->toArray() + $this->getRequest()->getPost()->toArray();
     $rManager = $this->getServiceLocator()->get('VuFind\\RecommendPluginManager');
     $setupCallback = function ($runner, $params, $searchId) use($rManager) {
         $listener = new RecommendListener($rManager, $searchId);
         $config = [];
         $rawConfig = $params->getOptions()->getRecommendationSettings($params->getSearchHandler());
         foreach ($rawConfig['side'] as $value) {
             $settings = explode(':', $value);
             if ($settings[0] === 'SideFacetsDeferred') {
                 $settings[0] = 'SideFacets';
                 $config['side'][] = implode(':', $settings);
             }
         }
         $listener->setConfig($config);
         $listener->attach($runner->getEventManager()->getSharedManager());
         $params->setLimit(0);
     };
     $runner = $this->getServiceLocator()->get('VuFind\\SearchRunner');
     $results = $runner->run($request, 'Solr', $setupCallback);
     if ($results instanceof \VuFind\Search\EmptySet\Results) {
         $this->setLogger($this->getServiceLocator()->get('VuFind\\Logger'));
         $this->logError('Solr faceting request failed');
         return $this->output('', self::STATUS_ERROR, 500);
     }
     $recommend = $results->getRecommendations('side');
     $recommend = reset($recommend);
     $view = $this->getViewRenderer();
     $view->recommend = $recommend;
     $view->params = $results->getParams();
     $view->searchClassId = 'Solr';
     $html = $view->partial('Recommend/SideFacets.phtml');
     return $this->output($html, self::STATUS_OK);
 }
예제 #4
0
 /**
  * Get the processed search results.
  *
  * @return \VuFind\Search\SolrCollection\Results
  */
 public function getResults()
 {
     if (null === $this->results) {
         $driver = $this->getRecordDriver();
         $request = $this->getRequest()->getQuery()->toArray() + $this->getRequest()->getPost()->toArray();
         $rManager = $this->recommendManager;
         $cb = function ($runner, $params, $searchId) use($driver, $rManager) {
             $params->initFromRecordDriver($driver);
             $listener = new RecommendListener($rManager, $searchId);
             $listener->setConfig($params->getOptions()->getRecommendationSettings());
             $listener->attach($runner->getEventManager()->getSharedManager());
         };
         $this->results = $this->runner->run($request, 'SolrCollection', $cb);
     }
     return $this->results;
 }