Skip to content
Snippets Groups Projects
Commit c4476fd2 authored by Alexander Purr's avatar Alexander Purr Committed by Dorian Merz
Browse files

refs #19646 [fid] copy mylistaction from finc\MyResearchController from finc

* set additional view context parameter
parent 1daccbbe
No related merge requests found
......@@ -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;
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment