diff --git a/module/fid/src/Controller/MyResearchController.php b/module/fid/src/Controller/MyResearchController.php index e8999fd059bfa4a98365614c85ed3a7d5ec98128..e0e032ed4b256207679c326f6c3484d69bad4dba 100644 --- a/module/fid/src/Controller/MyResearchController.php +++ b/module/fid/src/Controller/MyResearchController.php @@ -31,6 +31,8 @@ use fid\Service\Client; use fid\Service\ClientException; use fid\Service\DataTransferObject\Library; use VuFind\Exception\Forbidden; +use VuFind\Exception\ListPermission as ListPermissionException; +use VuFind\Search\RecommendListener; use Zend\ServiceManager\ServiceLocatorInterface; /** @@ -215,4 +217,80 @@ class MyResearchController extends \VuFind\Controller\MyResearchController return $licenses; } + + /** + * 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 ForbiddenException('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) { + $layout = $this->params()->fromPost( + 'layout', $this->params()->fromQuery('layout') + ); + + /* #17712 not necessary to fetch items after deleting by ajax */ + $success = $this->performDeleteFavorite($deleteId, $deleteSource); + if ($layout === 'lightbox' || $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->serviceLocator->get('VuFind\Search\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->serviceLocator + ->get('VuFind\Recommend\PluginManager'); + $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, 'context' => "favorite"] + ); + } catch (ListPermissionException $e) { + if (!$this->getUser()) { + return $this->forceLogin(); + } + throw $e; + } + } }