Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bulk favorites save from search results #3960

Merged
merged 9 commits into from
Oct 16, 2024
22 changes: 14 additions & 8 deletions module/VuFind/src/VuFind/Controller/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,20 @@ public function saveAction()
['cartIds' => $ids, 'cartAction' => 'Save']
);
}

$viewModel = $this->createViewModel(
[
'records' => $this->getRecordLoader()->loadBatch($ids),
'lists' => $this->getDbService(UserListServiceInterface::class)->getUserListsByUser($user),
]
);
if ($submitDisabled ?? false) {
return $viewModel;
}
if ($this->formWasSubmitted('newList')) {
return $this->forwardTo('MyResearch', 'editlist', ['id' => 'NEW']);
}
// Process submission if necessary:
if (!($submitDisabled ?? false) && $this->formWasSubmitted()) {
if ($this->formWasSubmitted()) {
$results = $this->getService(FavoritesService::class)
->saveRecordsToFavorites($this->getRequest()->getPost()->toArray(), $user);
$listUrl = $this->url()->fromRoute(
Expand All @@ -553,11 +564,6 @@ public function saveAction()
}

// Pass record and list information to view:
return $this->createViewModel(
[
'records' => $this->getRecordLoader()->loadBatch($ids),
'lists' => $this->getDbService(UserListServiceInterface::class)->getUserListsByUser($user),
]
);
return $viewModel;
}
}
16 changes: 8 additions & 8 deletions module/VuFind/src/VuFind/Controller/MyResearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use VuFind\Crypt\SecretCalculator;
use VuFind\Db\Entity\SearchEntityInterface;
use VuFind\Db\Entity\UserEntityInterface;
use VuFind\Db\Entity\UserListEntityInterface;
use VuFind\Db\Service\SearchServiceInterface;
use VuFind\Db\Service\UserListServiceInterface;
use VuFind\Db\Service\UserResourceServiceInterface;
Expand Down Expand Up @@ -1201,14 +1202,10 @@ protected function processEditList(UserEntityInterface $user, $list)
$this->params()->fromQuery('ids', [])
);
if (!empty($bulkIds)) {
$params = [];
foreach ($bulkIds as $id) {
$params[] = urlencode('ids[]') . '=' . urlencode($id);
}
$saveUrl = $this->url()->fromRoute('cart-save');
$saveUrl .= (!str_contains($saveUrl, '?')) ? '?' : '&';
return $this->redirect()
->toUrl($saveUrl . implode('&', $params));
// Add final id of the list to request post so cartcontroller saveaction
// can properly load the list
$this->getRequest()->getPost()->set('list', $finalId);
return $this->forwardTo('Cart', 'Save');
}

return $this->redirect()->toRoute('userList', ['id' => $finalId]);
Expand Down Expand Up @@ -1267,12 +1264,15 @@ public function editlistAction()
$listTags = $favoritesService
->formatTagStringForEditing($tagsService->getListTags($list, $list->getUser()));
}
$recordIds = $this->params()->fromQuery('ids', $this->params()->fromPost('ids', []));
$records = $this->getRecordLoader()->loadBatch($recordIds);
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
// Send the list to the view:
return $this->createViewModel(
[
'list' => $list,
'newList' => $newList,
'listTags' => $listTags,
'records' => $records,
]
);
}
Expand Down
4 changes: 1 addition & 3 deletions themes/bootstrap3/templates/cart/save.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

<?php if (count($this->records) > 0): ?>
<form class="form-cart-save" method="post" action="<?=$this->url('cart-save')?>" name="bulkSave">
<?php $idParams = []; ?>
<?php foreach ($this->records as $current): ?>
<?php $idParams[] = urlencode('ids[]') . '=' . urlencode($current->getSourceIdentifier() . '|' . $current->getUniqueId()) ?>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtmlAttr($current->getSourceIdentifier() . '|' . $current->getUniqueId())?>">
<?php endforeach; ?>
<div class="form-group">
Expand Down Expand Up @@ -48,7 +46,7 @@
<option value=""><?=$this->transEsc('default_list_title') ?></option>
<?php endif; ?>
</select>
<a class="btn btn-link" id="make-list" href="<?=$this->url('editList', ['id' => 'NEW']) . '?' . implode('&amp;', $idParams) ?>"><?=$this->transEsc('or create a new list'); ?></a>
<button type="button" id="make-list" name="newList" class="btn btn-link"><?=$this->transEsc('or create a new list'); ?></button>
</div>

<?php if ($this->usertags()->getMode() !== 'disabled'): ?>
Expand Down
5 changes: 4 additions & 1 deletion themes/bootstrap3/templates/myresearch/editlist.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

<h2><?=$this->transEsc($pageTitle); ?></h2>

<form class="form-edit-list" method="post" name="<?=$this->newList ? 'newList' : 'editListForm'?>">
<form class="form-edit-list" method="post" name="<?=$this->newList ? 'newList' : 'editListForm'?>" action="<?=$this->url('editList'); ?>">
<input type="hidden" name="id" value="<?=empty($listId = $this->list->getId()) ? 'NEW' : $this->escapeHtmlAttr($listId) ?>">
<?php foreach ($this->records ?? [] as $current): ?>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtmlAttr($current->getSourceIdentifier() . '|' . $current->getUniqueId())?>">
<?php endforeach; ?>
<div class="form-group">
<label class="control-label" for="list_title"><?=$this->transEsc('List'); ?>:</label>
<input id="list_title" class="form-control" type="text" name="title" value="<?=$this->escapeHtmlAttr($this->list->getTitle())?>">
Expand Down
4 changes: 1 addition & 3 deletions themes/bootstrap5/templates/cart/save.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

<?php if (count($this->records) > 0): ?>
<form class="form-cart-save" method="post" action="<?=$this->url('cart-save')?>" name="bulkSave">
<?php $idParams = []; ?>
<?php foreach ($this->records as $current): ?>
<?php $idParams[] = urlencode('ids[]') . '=' . urlencode($current->getSourceIdentifier() . '|' . $current->getUniqueId()) ?>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtmlAttr($current->getSourceIdentifier() . '|' . $current->getUniqueId())?>">
<?php endforeach; ?>
<div class="form-group">
Expand Down Expand Up @@ -48,7 +46,7 @@
<option value=""><?=$this->transEsc('default_list_title') ?></option>
<?php endif; ?>
</select>
<a class="btn btn-link" id="make-list" href="<?=$this->url('editList', ['id' => 'NEW']) . '?' . implode('&amp;', $idParams) ?>"><?=$this->transEsc('or create a new list'); ?></a>
<button type="button" id="make-list" name="newList" class="btn btn-link"><?=$this->transEsc('or create a new list'); ?></button>
</div>

<?php if ($this->usertags()->getMode() !== 'disabled'): ?>
Expand Down
5 changes: 4 additions & 1 deletion themes/bootstrap5/templates/myresearch/editlist.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

<h2><?=$this->transEsc($pageTitle); ?></h2>

<form class="form-edit-list" method="post" name="<?=$this->newList ? 'newList' : 'editListForm'?>">
<form class="form-edit-list" method="post" name="<?=$this->newList ? 'newList' : 'editListForm'?>" action="<?=$this->url('editList'); ?>">
<input type="hidden" name="id" value="<?=empty($listId = $this->list->getId()) ? 'NEW' : $this->escapeHtmlAttr($listId) ?>">
<?php foreach ($this->records ?? [] as $current): ?>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtmlAttr($current->getSourceIdentifier() . '|' . $current->getUniqueId())?>">
<?php endforeach; ?>
<div class="form-group">
<label class="control-label" for="list_title"><?=$this->transEsc('List'); ?>:</label>
<input id="list_title" class="form-control" type="text" name="title" value="<?=$this->escapeHtmlAttr($this->list->getTitle())?>">
Expand Down
Loading