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

[FINNA-2767] Initial implementation of disec support for reservation lists #3091

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7c15adb
Initial implementation of disec support for reservation lists
LuomaJuha Nov 28, 2024
a8a59ae
Adjusted to log values, added ReservationListStatus enumerator
LuomaJuha Nov 29, 2024
9adda13
Merge branch 'dev' into reservationlist-disec-implementation
LuomaJuha Dec 3, 2024
412e76b
Review fixes
LuomaJuha Dec 5, 2024
64f5ee2
Adjusted sample file to match
LuomaJuha Dec 5, 2024
f18570f
Added missing empty translation
LuomaJuha Dec 5, 2024
389e207
Moved properties to proper class
LuomaJuha Dec 5, 2024
83221b9
Adjusted keys
LuomaJuha Dec 5, 2024
04db089
Fixed typos in translations, moved Connection specific classes to the…
LuomaJuha Dec 10, 2024
8427a2d
Manipulate post params less, use form more properly.
LuomaJuha Dec 11, 2024
371302a
Adjusted setListOrdered default values set
LuomaJuha Dec 11, 2024
a5f3652
Moved reservation list specific form functionality to its own class
LuomaJuha Dec 11, 2024
ea5f3bc
Removed unused parts of code
LuomaJuha Dec 11, 2024
94fa86a
Readded in_process as it is a plausible state for order, adjusted com…
LuomaJuha Dec 11, 2024
030f466
Revert php versions to 8
LuomaJuha Dec 11, 2024
7c9b98f
And also this one
LuomaJuha Dec 11, 2024
8add8c4
Adjusted to not use feedback
LuomaJuha Jan 3, 2025
2a072c7
Removed sample from feedbackforms.yaml.sample
LuomaJuha Jan 3, 2025
d5515e6
Removed odd variable from default values
LuomaJuha Jan 3, 2025
01dac99
Adjusted param types
LuomaJuha Jan 3, 2025
ef99018
Renamed to match handler instead of connection
LuomaJuha Jan 14, 2025
ae47fcd
Adjusted comments
LuomaJuha Jan 14, 2025
61d0be0
Adjusted variable name in reservationlistservice
LuomaJuha Jan 15, 2025
a7873af
Line length fix
LuomaJuha Jan 15, 2025
e40eaea
removed switch case from reservationlist ajax handler
LuomaJuha Jan 15, 2025
a7501a9
Adjusted to use function defined in abstractbase to fetch required va…
LuomaJuha Jan 15, 2025
cd30dcb
Removed some calls to helper
LuomaJuha Jan 15, 2025
57d01e7
Update module/Finna/src/Finna/ReservationList/ReservationListService.php
LuomaJuha Jan 15, 2025
8d2cfc1
Update module/Finna/src/Finna/ReservationList/ReservationListService.php
LuomaJuha Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion local/config/finna/ReservationList.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ PlaceOrder:
post: ReservationList::request_post_info_html

fields:
- name: record_ids
- name: record_ids_text
type: textarea
label: ReservationList::Reservation Resources
settings:
Expand Down
25 changes: 11 additions & 14 deletions module/Finna/src/Finna/AjaxHandler/ReservationList.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,17 @@ public function handleRequest(Params $params)
);
}
$result = [];
switch ($params->fromQuery('type')) {
case 'status':
$listProperties = $this->reservationListService->getListProperties(
$list->getInstitution(),
$list->getListConfigIdentifier()
);
$connectionType = $list->getConnection();
$handler = $this->connectionHandler->get($connectionType);
$handler->init($listProperties['properties']);
$response = $handler->getListStatus($list, $this->user);
$result['status'] = $this->translate($response);
break;
default:
break;
$type = $params->fromQuery('type');
if ('status' === $type) {
$listProperties = $this->reservationListService->getListProperties(
$list->getInstitution(),
$list->getListConfigIdentifier()
)['properties'];
$handler = $this->connectionHandler->getWithConfig($listProperties);
$response = $handler->getListStatus($list, $this->user);
$result['status'] = $this->translate($response);
} else {
return $this->formatResponse('Bad request', self::STATUS_HTTP_BAD_REQUEST);
}
return $this->formatResponse($result);
}
Expand Down
25 changes: 6 additions & 19 deletions module/Finna/src/Finna/Controller/ReservationListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function addItemToListAction()
$view->source ?: DEFAULT_SEARCH_BACKEND,
false
);
$listProperties = ($this->reservationListHelper)($user)->getListProperties(
$listProperties = $this->reservationListService->getListProperties(
$view->institution,
$view->listIdentifier
)['properties'];
Expand Down Expand Up @@ -208,7 +208,7 @@ public function createListAction(): \Laminas\View\Model\ViewModel
'listIdentifier' => $this->getParam('listIdentifier'),
]
);
$listProperties = ($this->reservationListHelper)($user)->getListProperties(
$listProperties = $this->reservationListService->getListProperties(
$view->institution,
$view->listIdentifier
)['properties'];
Expand Down Expand Up @@ -295,31 +295,18 @@ public function placeOrderAction()
if ($list->getOrdered()) {
throw new \VuFind\Exception\Forbidden('List already ordered');
}
$listProperties = $this->reservationListHelper->getListProperties(
$listProperties = $this->reservationListService->getListProperties(
$list->getInstitution(),
$list->getListConfigIdentifier()
)['properties'];
if (!($listProperties['Enabled'] ?? true)) {
throw new \VuFind\Exception\Forbidden('ReservationList: No list properties found.');
}

$postValues = $request->getPost()->toArray();
$listSpecificValues = [
'rl_list_id' => $listId,
'rl_institution' => $list->getInstitution(),
'rl_list_identifier' => $list->getListConfigIdentifier(),
'record_ids' => '',
'resourceIDs' => [],
];
foreach ($this->reservationListService->getResourcesForList($list, $user) as $resource) {
$listSpecificValues['record_ids'] .= $resource->getRecordId() . '||' . $resource->getTitle() . PHP_EOL;
$listSpecificValues['resourceIDs'][] = $resource->getSource() . '|' . $resource->getRecordId();
}
$gatheredValues = array_merge($postValues, $listSpecificValues);

$handler = $this->getService(\Finna\ReservationList\Handler\PluginManager::class)
->getWithConfig($listProperties);
$form = $handler->getPlaceOrderForm($gatheredValues);
$orderSpecificValues = $handler->getValuesForPlaceOrderForm($list, $user, $request->getPost()->toArray());
$form = $handler->getPlaceOrderForm($orderSpecificValues);

$formId = ConnectionAbstractBase::FORM_ID;
$view = $this->createViewModel(compact('form', 'formId', 'user'));
Expand All @@ -340,7 +327,7 @@ public function placeOrderAction()
if (!$form->isValid()) {
return $view;
}
$result = $handler->placeOrder($gatheredValues, $user);
$result = $handler->placeOrder($orderSpecificValues, $user);
if ($result['success']) {
$this->reservationListService->setListOrdered($user, $list, $result);
$this->flashMessenger()->addSuccessMessage($form->getSubmitResponse());
Expand Down
46 changes: 46 additions & 0 deletions module/Finna/src/Finna/ReservationList/Handler/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ abstract class AbstractBase implements HandlerInterface, \Laminas\Log\LoggerAwar
*/
public const FORM_ID = 'ReservationListRequest';

/**
* Keys to look for in an array to be returned when searching for requested params.
*
* @var array
*/
public const PLACE_ORDER_REQUEST_KEYS = [
'firstName' => '',
'lastName' => '',
'phone' => '',
'email' => '',
'pickup_date' => '',
'message' => '',
];

/**
* Order form configuration defined.
*
Expand All @@ -81,6 +95,38 @@ public function __construct(ContainerInterface $serviceLocator)
$this->serviceLocator = $serviceLocator;
}

/**
* Get values required for placing the order.
*
* @param FinnaResourceListEntityInterface $list List being ordered
* @param UserEntityInterface $user User who owns the list
* @param array $requestValues Values obtained i.e from post request as array
*
* @return array
*/
public function getValuesForPlaceOrderForm(
FinnaResourceListEntityInterface $list,
UserEntityInterface $user,
array $requestValues
): array {
$result = [
'rl_list_id' => $list->getId(),
'rl_institution' => $list->getInstitution(),
'rl_list_identifier' => $list->getListConfigIdentifier(),
'record_ids_text' => '',
'record_source_and_ids' => [],
];
$reservationListService = $this->getService(\Finna\ReservationList\ReservationListService::class);
foreach ($reservationListService->getResourcesForList($list, $user) as $resource) {
$result['record_ids_text'] .= $resource->getRecordId() . '||' . $resource->getTitle() . PHP_EOL;
$result['record_source_and_ids'][] = $resource->getSource() . '|' . $resource->getRecordId();
}
foreach (array_intersect_key($requestValues, self::PLACE_ORDER_REQUEST_KEYS) as $foundKey => $value) {
$result[$foundKey] = $requestValues[$foundKey];
}
return $result;
}

/**
* Build form with configuration obtained from ReservationList.yaml <Action>Forms section.
*
Expand Down
2 changes: 1 addition & 1 deletion module/Finna/src/Finna/ReservationList/Handler/Disec.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function placeOrder(array $formValues, UserEntityInterface $user): array

$resources = [];
$recordLoader = $this->getService(\VuFind\Record\Loader::class);
foreach ($recordLoader->loadBatch($formValues['resourceIDs']) as $record) {
foreach ($recordLoader->loadBatch($formValues['record_source_and_ids']) as $record) {
if ($identifiers = $record->tryMethod('getIdentifier', [])) {
$resources[] = array_shift($identifiers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ public function placeOrder(array $formValues, UserEntityInterface $user): array;
*/
public function getListStatus(FinnaResourceListEntityInterface $list): string;

/**
* Get values required for placing the order.
*
* @param FinnaResourceListEntityInterface $list List being ordered
* @param UserEntityInterface $user User who owns the list
* @param array $requestValues Values obtained i.e from post request as array
*
* @return array
*/
public function getValuesForPlaceOrderForm(
FinnaResourceListEntityInterface $list,
UserEntityInterface $user,
array $requestValues
): array;

/**
* Get form used for placing orders.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ReservationListService implements TranslatorAwareInterface, DbServiceAware
* @param ?RecordCache $recordCache Record cache (optional)
* @param ?Container $session Session container for remembering
* state (optional)
* @param ?array $yamlConfig Reservation list yaml config
* @param ?array $reservationListConfig ReservationList.yaml as array
LuomaJuha marked this conversation as resolved.
Show resolved Hide resolved
*/
public function __construct(
protected FinnaResourceListServiceInterface $resourceListService,
Expand All @@ -128,7 +128,7 @@ public function __construct(
protected RecordLoader $recordLoader,
protected ?RecordCache $recordCache = null,
protected ?Container $session = null,
protected ?array $yamlConfig = []
protected ?array $reservationListConfig = []
LuomaJuha marked this conversation as resolved.
Show resolved Hide resolved
) {
}

Expand Down Expand Up @@ -554,12 +554,13 @@ public function getListProperties(
string $institution,
string $listIdentifier
): array {
foreach ($this->yamlConfig['Institutions'][$institution]['Lists'] ?? [] as $list) {
foreach ($this->reservationListConfig['Institutions'][$institution]['Lists'] ?? [] as $list) {
$list = $this->ensureListKeys($list);
if ($list['Identifier'] === $listIdentifier) {
return [
'properties' => $list,
'institution_information' => $this->yamlConfig['Institutions'][$institution]['Information'] ?? [],
'institution_information'
=> $this->reservationListConfig['Institutions'][$institution]['Information'] ?? [],
'translation_keys' => [
'title' => "ReservationList::list_title_{$institution}_{$listIdentifier}",
'description' => "ReservationList::list_description_{$institution}_{$listIdentifier}",
Expand Down
Loading