From 7c15adb4633376f0e0cc6f35bcb47049fee2e602 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 28 Nov 2024 16:36:25 +0200 Subject: [PATCH 01/15] Initial implementation of disec support for reservation lists --- module/Finna/config/module.config.php | 5 + module/Finna/sql/mysql.sql | 1 + .../src/Finna/AjaxHandler/ReservationList.php | 112 +++++++++++ .../AjaxHandler/ReservationListFactory.php | 75 ++++++++ .../Controller/ReservationListController.php | 30 ++- .../FinnaResourceListEntityInterface.php | 17 ++ .../src/Finna/Db/Row/FinnaResourceList.php | 23 +++ .../Finna/ReservationList/AbstractBase.php | 134 +++++++++++++ .../ReservationList/ConnectionFactory.php | 67 +++++++ .../ReservationList/ConnectionInterface.php | 78 ++++++++ .../src/Finna/ReservationList/Database.php | 43 +++++ .../Finna/src/Finna/ReservationList/Disec.php | 176 ++++++++++++++++++ .../Finna/ReservationList/PluginManager.php | 95 ++++++++++ .../ReservationListService.php | 96 +++++++++- .../ReservationListServiceFactory.php | 5 +- .../View/Helper/Root/ReservationList.php | 139 +++++--------- themes/finna2/js/finna-reservation-list.js | 31 +++ themes/finna2/js/finna.js | 1 + themes/finna2/less/finna/reservationlist.less | 3 + themes/finna2/scss/finna/reservationlist.scss | 3 + .../reservationlist/displaylist.phtml | 4 + themes/finna2/theme.config.php | 1 + 22 files changed, 1023 insertions(+), 116 deletions(-) create mode 100644 module/Finna/src/Finna/AjaxHandler/ReservationList.php create mode 100644 module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php create mode 100644 module/Finna/src/Finna/ReservationList/AbstractBase.php create mode 100644 module/Finna/src/Finna/ReservationList/ConnectionFactory.php create mode 100644 module/Finna/src/Finna/ReservationList/ConnectionInterface.php create mode 100644 module/Finna/src/Finna/ReservationList/Database.php create mode 100644 module/Finna/src/Finna/ReservationList/Disec.php create mode 100644 module/Finna/src/Finna/ReservationList/PluginManager.php create mode 100644 themes/finna2/js/finna-reservation-list.js diff --git a/module/Finna/config/module.config.php b/module/Finna/config/module.config.php index d5fd5a7c3f1..60459fbc7ca 100644 --- a/module/Finna/config/module.config.php +++ b/module/Finna/config/module.config.php @@ -381,6 +381,7 @@ 'Finna\Statistics\Driver\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'Finna\Statistics\EventHandler' => 'Finna\Statistics\EventHandlerFactory', \Finna\ReservationList\ReservationListService::class => \Finna\ReservationList\ReservationListServiceFactory::class, + \Finna\ReservationList\PluginManager::class => \VuFind\ServiceManager\AbstractPluginManagerFactory::class, 'Finna\Favorites\FavoritesService' => 'Finna\Favorites\FavoritesServiceFactory', 'Finna\View\CustomElement\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'Finna\Video\Handler\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', @@ -493,6 +494,8 @@ 'Finna\AjaxHandler\GetUserListFactory', 'Finna\AjaxHandler\GetUserLists' => 'Finna\AjaxHandler\GetUserListsFactory', + 'Finna\AjaxHandler\ReservationList' => + 'Finna\AjaxHandler\ReservationListFactory', 'Finna\AjaxHandler\ImportFavorites' => 'Finna\AjaxHandler\ImportFavoritesFactory', 'Finna\AjaxHandler\OnlinePaymentNotify' => @@ -533,6 +536,7 @@ 'getSearchTabsRecommendations' => 'Finna\AjaxHandler\GetSearchTabsRecommendations', 'getSimilarRecords' => 'Finna\AjaxHandler\GetSimilarRecords', 'getUserList' => 'Finna\AjaxHandler\GetUserList', + 'reservationList' => 'Finna\AjaxHandler\ReservationList', 'importFavorites' => 'Finna\AjaxHandler\ImportFavorites', 'onlinePaymentNotify' => 'Finna\AjaxHandler\OnlinePaymentNotify', 'registerOnlinePayment' => 'Finna\AjaxHandler\RegisterOnlinePayment', @@ -766,6 +770,7 @@ ], 'onlinepayment_handler' => [ /* see Finna\OnlinePayment\Handler\PluginManager for defaults */ ], 'video_handler' => [ /* see Finna\Video\Handler\PluginManager for defaults */ ], + 'reservationlist' => [ /* see Finna\ReservationList\PluginManager for defaults */ ], 'recommend' => [ 'factories' => [ 'VuFind\Recommend\CollectionSideFacets' => 'Finna\Recommend\Factory::getCollectionSideFacets', diff --git a/module/Finna/sql/mysql.sql b/module/Finna/sql/mysql.sql index 544510fd9d3..debb3de2983 100644 --- a/module/Finna/sql/mysql.sql +++ b/module/Finna/sql/mysql.sql @@ -341,6 +341,7 @@ CREATE TABLE `finna_resource_list` ( `ordered` datetime DEFAULT NULL, `pickup_date` datetime DEFAULT NULL, `connection` varchar(40) NOT NULL DEFAULT 'database', + `external_id` varchar(40) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), CONSTRAINT `resource_list_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationList.php b/module/Finna/src/Finna/AjaxHandler/ReservationList.php new file mode 100644 index 00000000000..56fdf6009d9 --- /dev/null +++ b/module/Finna/src/Finna/AjaxHandler/ReservationList.php @@ -0,0 +1,112 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ + +namespace Finna\AjaxHandler; + +use Finna\ReservationList\PluginManager; +use Finna\ReservationList\ReservationListService; +use Laminas\Mvc\Controller\Plugin\Params; +use VuFind\Db\Entity\UserEntityInterface; +use VuFind\I18n\Translator\TranslatorAwareInterface; + +/** + * Reservation list ajax handler + * + * @category VuFind + * @package AjaxHandler + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ +class ReservationList extends \VuFind\AjaxHandler\AbstractBase implements TranslatorAwareInterface +{ + use \VuFind\I18n\Translator\TranslatorAwareTrait; + + /** + * Constructor + * + * @param ?UserEntityInterface $user Logged in user (or null) + * @param ReservationListService $reservationListService Reservation list service + * @param PluginManager $connectionHandler Reservation List connection handler + */ + public function __construct( + protected ?UserEntityInterface $user, + protected ReservationListService $reservationListService, + protected PluginManager $connectionHandler, + ) { + } + + /** + * Handle a request. + * + * @param Params $params Parameter helper from controller + * + * @return array [response data, HTTP status code] + */ + public function handleRequest(Params $params) + { + if ($this->user === null) { + return $this->formatResponse( + $this->translate('You must be logged in first'), + self::STATUS_HTTP_NEED_AUTH + ); + } + $listId = (int)$params->fromQuery('list_id'); + if (!$listId) { + return $this->formatResponse( + 'Bad request', + self::STATUS_HTTP_BAD_REQUEST + ); + } + $list = $this->reservationListService->getListById($listId, $this->user); + if (!$list) { + return $this->formatResponse( + 'Bad request', + self::STATUS_HTTP_BAD_REQUEST + ); + } + $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']); + $result = $handler->getListStatus($list, $this->user); + $result = $this->translate(['ReservationList', 'status_' . $result]); + break; + default: + break; + } + return $this->formatResponse($result); + } +} diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php b/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php new file mode 100644 index 00000000000..fb58a3171c4 --- /dev/null +++ b/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php @@ -0,0 +1,75 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ + +namespace Finna\AjaxHandler; + +use Psr\Container\ContainerInterface; + +/** + * Reservation list ajax handler + * + * @category VuFind + * @package AjaxHandler + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ +class ReservationListFactory implements \Laminas\ServiceManager\Factory\FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function __invoke( + ContainerInterface $container, + $requestedName, + array $options = null + ) { + if (!empty($options)) { + throw new \Exception('Unexpected options passed to factory.'); + } + return new $requestedName( + $container->get(\VuFind\Auth\Manager::class)->getUserObject(), + $container->get(\Finna\ReservationList\ReservationListService::class), + $container->get(\Finna\ReservationList\PluginManager::class), + ); + } +} diff --git a/module/Finna/src/Finna/Controller/ReservationListController.php b/module/Finna/src/Finna/Controller/ReservationListController.php index b5ce25123c1..58c62a6e2d4 100644 --- a/module/Finna/src/Finna/Controller/ReservationListController.php +++ b/module/Finna/src/Finna/Controller/ReservationListController.php @@ -305,25 +305,21 @@ public function placeOrderAction() $formId = Form::RESERVATION_LIST_REQUEST; $resourcesText = ''; + $resourceIds = []; foreach ($this->reservationListService->getResourcesForList($list, $user) as $resource) { $resourcesText .= $resource->getRecordId() . '||' . $resource->getTitle() . PHP_EOL; + $resourceIds[] = $resource->getSource() . '|' . $resource->getRecordId(); } // Set reservationlist specific form values $request->getPost() ->set('rl_list_id', $listId) ->set('rl_institution', $list->getInstitution()) ->set('rl_list_identifier', $list->getListConfigIdentifier()) - ->set('record_ids', $resourcesText); + ->set('record_ids', $resourcesText) + ->set('resourceIDs', $resourceIds); $form = $this->getService(\Finna\Form\Form::class); - $params = []; - if ($refererHeader = $this->getRequest()->getHeader('Referer')) { - $params['referrer'] = $refererHeader->getFieldValue(); - } - if ($userAgentHeader = $this->getRequest()->getHeader('User-Agent')) { - $params['userAgent'] = $userAgentHeader->getFieldValue(); - } - $form->setFormId($formId, $params, $request->getPost()->toArray()); + $form->setFormId(formId: $formId, prefill: $request->getPost()->toArray()); if (!$form->isEnabled()) { throw new \VuFind\Exception\Forbidden("Form '$formId' is disabled"); @@ -333,12 +329,12 @@ public function placeOrderAction() $view->setTemplate('feedback/form'); $view->useCaptcha = false; - $params = $this->params(); $form->setData($request->getPost()->toArray()); if (!$this->formWasSubmitted(useCaptcha: false)) { $form->setData( [ - 'name' => trim($user->getFirstname() . ' ' . $user->getLastname()), + 'firstName' => $user->getFirstname(), + 'lastName' => $user->getLastname(), 'email' => $user->getEmail(), ] ); @@ -348,12 +344,12 @@ public function placeOrderAction() if (!$form->isValid()) { return $view; } - - // Override recipients to match list's configured recipients: - $request->getPost()->set('recipient', $listProperties['Recipient']); - $primaryHandler = $form->getPrimaryHandler(); - $success = $primaryHandler->handle($form, $params, $user); - if ($success) { + $connectionType = $listProperties['Connection']['type']; + $handler = $this->getService(\Finna\ReservationList\PluginManager::class)->get($connectionType); + $handler->init($listProperties); + $result = $handler->placeOrder($this->params(), $user, $form); + if ($result['success']) { + $request->getPost()->set('external_id', $result['external_id'])->set('connection', $connectionType); $this->reservationListService->setListOrdered($user, $list, $request->getPost()); $this->flashMessenger()->addSuccessMessage($form->getSubmitResponse()); return $this->getRefreshResponse(); diff --git a/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php b/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php index 779626ae93e..f16f36afd0b 100644 --- a/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php +++ b/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php @@ -55,6 +55,7 @@ * @property string $ordered * @property string $pickup_date * @property string $connection + * @property string $external_id */ interface FinnaResourceListEntityInterface extends EntityInterface { @@ -222,4 +223,20 @@ public function getConnection(): string; * @return static */ public function setConnection(string $connection): static; + + /** + * Get external id + * + * @return ?string + */ + public function getExternalId(): ?string; + + /** + * Set external id + * + * @param string $id External id + * + * @return static + */ + public function setExternalId(string $id): static; } diff --git a/module/Finna/src/Finna/Db/Row/FinnaResourceList.php b/module/Finna/src/Finna/Db/Row/FinnaResourceList.php index ff6f7807ccc..cd5d3dc7a5c 100644 --- a/module/Finna/src/Finna/Db/Row/FinnaResourceList.php +++ b/module/Finna/src/Finna/Db/Row/FinnaResourceList.php @@ -314,4 +314,27 @@ public function setListConfigIdentifier(string $listConfigIdentifier): static $this->list_config_identifier = $listConfigIdentifier; return $this; } + + /** + * Get the external id + * + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->external_id; + } + + /** + * Set the external id + * + * @param string $id External id + * + * @return static + */ + public function setExternalId(string $id): static + { + $this->external_id = $id; + return $this; + } } diff --git a/module/Finna/src/Finna/ReservationList/AbstractBase.php b/module/Finna/src/Finna/ReservationList/AbstractBase.php new file mode 100644 index 00000000000..ea5bade553c --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/AbstractBase.php @@ -0,0 +1,134 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ + +namespace Finna\ReservationList; + +use Finna\Db\Entity\FinnaResourceListEntityInterface; +use Laminas\Mvc\Controller\Plugin\Params; +use Psr\Container\ContainerInterface; +use VuFind\Db\Entity\UserEntityInterface; +use VuFind\Form\Form; +use VuFind\Service\GetServiceTrait; + +/** + * Disec connection handler + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +class AbstractBase implements ConnectionInterface +{ + use GetServiceTrait; + + /** + * Default unknown status + * + * @var string + */ + public const STATUS_UNKNOWN = 'UNKNOWN'; + + /** + * Recipients for email handler defined in ReservationList.yaml + * + * @var array + */ + protected array $recipients; + + /** + * Configured handler to handle form post, defaults to email handler + * + * @var string + */ + protected string $configuredHandler = 'email'; + + /** + * Constructor + * + * @param ContainerInterface $serviceLocator Service locator used with GetServiceTrait + */ + public function __construct(ContainerInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + } + + /** + * Places an order + * + * @param Params $params Parameters containing data from posting place order form + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order + * + * @return array [external_id: Id in external service or null, success: true or false] + */ + public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array + { + $params->getController()->getRequest()->getPost()->set('recipient', $this->recipients); + $formPluginManager = $this->getService(\VuFind\Form\Handler\PluginManager::class); + $result = $formPluginManager->get($this->configuredHandler)->handle($form, $params, $user); + return [ + 'success' => $result, + 'external_id' => null, + ]; + } + + /** + * Check list status. Used for external services. + * + * @param FinnaResourceListEntityInterface $list List to check for status + * @param UserEntityInterface $user Current logged in user + * + * @return string + */ + public function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string + { + return self::STATUS_UNKNOWN; + } + + /** + * Initialize connection handler + * + * @param array $config List specific configuration from ReservationList.yaml + * + * @return static + * @throws \Exception If Database connection is not configured properly + */ + public function init(array $config): self + { + try { + $this->recipients = $config['Recipient']; + $this->configuredHandler = $config['Connection']['handler'] ?? 'email'; + } catch (\Exception $e) { + throw new \Exception('Database: Invalid configuration'); + } + return $this; + } +} diff --git a/module/Finna/src/Finna/ReservationList/ConnectionFactory.php b/module/Finna/src/Finna/ReservationList/ConnectionFactory.php new file mode 100644 index 00000000000..b93bb4db4bf --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/ConnectionFactory.php @@ -0,0 +1,67 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ + +namespace Finna\ReservationList; + +use Laminas\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; + +/** + * Reservation list plugin factory + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ +class ConnectionFactory implements FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + if (!empty($options)) { + throw new \Exception('Unexpected options sent to factory.'); + } + return new $requestedName($container); + } +} diff --git a/module/Finna/src/Finna/ReservationList/ConnectionInterface.php b/module/Finna/src/Finna/ReservationList/ConnectionInterface.php new file mode 100644 index 00000000000..316920bc6a7 --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/ConnectionInterface.php @@ -0,0 +1,78 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ + +namespace Finna\ReservationList; + +use Finna\Db\Entity\FinnaResourceListEntityInterface; +use Laminas\Mvc\Controller\Plugin\Params; +use VuFind\Db\Entity\UserEntityInterface; +use VuFind\Form\Form; + +/** + * Reservation list connection plugin interface + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ +interface ConnectionInterface +{ + /** + * Places an order + * + * @param Params $params Parameters containing data from posting place order form + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order + * + * @return array [external_id: Id in external service or null, success: true or false] + */ + public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array; + + /** + * Check list status. Used for external services. + * + * @param FinnaResourceListEntityInterface $list List to check for status + * @param UserEntityInterface $user Current logged in user + * + * @return string + */ + public function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string; + + /** + * Initialize connection handler + * + * @param array $config List specific configuration from ReservationList.yaml + * + * @return static + * @throws \Exception If connection is not configured properly + */ + public function init(array $config): self; +} diff --git a/module/Finna/src/Finna/ReservationList/Database.php b/module/Finna/src/Finna/ReservationList/Database.php new file mode 100644 index 00000000000..245a8055110 --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/Database.php @@ -0,0 +1,43 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ + +namespace Finna\ReservationList; + +/** + * Database connection handler + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +class Database extends AbstractBase +{ +} diff --git a/module/Finna/src/Finna/ReservationList/Disec.php b/module/Finna/src/Finna/ReservationList/Disec.php new file mode 100644 index 00000000000..b6ea2ac32de --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/Disec.php @@ -0,0 +1,176 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ + +namespace Finna\ReservationList; + +use Finna\Db\Entity\FinnaResourceListEntityInterface; +use Laminas\Mvc\Controller\Plugin\Params; +use VuFind\Db\Entity\UserEntityInterface; +use VuFind\Form\Form; + +/** + * Disec connection handler + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +class Disec extends AbstractBase +{ + /** + * Disec orders url + * + * @param string + */ + protected $ordersUrl; + + /** + * API key used for disec authorization + * + * @param string + */ + protected $apiKey; + + /** + * Places an order + * + * @param Params $params Parameters containing data from posting place order form + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order + * + * @return array [external_id: Id in external service or null, success: true or false] + */ + public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array + { + if (!$this->ordersUrl) { + throw new \Exception('Invalid configuration.'); + } + $data = []; + $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($this->ordersUrl); + $client->setHeaders( + [ + 'Content-Type: application/json', + 'accept: */*', + 'X-API-Key: ' . $this->apiKey, + ] + ); + $client->setMethod(\Laminas\Http\Request::METHOD_POST); + + $resources = []; + $recordLoader = $this->getService(\VuFind\Record\Loader::class); + foreach ($recordLoader->loadBatch($params->fromPost('resourceIDs', [])) as $record) { + if ($identifiers = $record->tryMethod('getIdentifier', [])) { + $resources[] = array_shift($identifiers); + } + } + $data = [ + 'resourceIds' => $resources, + 'customer' => [ + 'firstName' => $params->fromPost('firstName') ?? $user->getFirstname(), + 'lastName' => $params->fromPost('lastName') ?? $user->getLastname(), + 'email' => $params->fromPost('email') ?? $user->getEmail(), + ], + 'contentInfo' => $params->fromPost('message', '') . PHP_EOL, + ]; + $data['contentInfo'] .= $params->fromPost('pickup_date', '') . PHP_EOL; + if ($catId = $user->getCatId()) { + [, $id] = explode('.', $catId); + $data['contentInfo'] .= 'cat_id: ' . $id; + } + $client->setRawBody(json_encode($data)); + $response = $client->send(); + + if ($response->isSuccess()) { + $body = json_decode($response->getBody(), true); + return [ + 'success' => true, + 'external_id' => $body['id'], + ]; + } + return [ + 'success' => false, + 'external_id' => null, + ]; + } + + /** + * Check list status. Used for external services. + * + * @param FinnaResourceListEntityInterface $list List to check for status + * @param UserEntityInterface $user Current logged in user + * + * @return string + */ + public function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string + { + $externalId = $list->getExternalId(); + $formedUrl = implode('/', [$this->ordersUrl, $externalId]); + $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($formedUrl); + $client->setHeaders( + [ + 'Content-Type: application/json', + 'accept: */*', + 'X-API-Key: ' . $this->apiKey, + ] + ); + $client->setMethod(\Laminas\Http\Request::METHOD_GET); + $response = $client->send(); + + if ($response->isSuccess()) { + $body = json_decode($response->getBody(), true); + return $body['status'] ?? self::STATUS_UNKNOWN; + } + return self::STATUS_UNKNOWN; + } + + /** + * Initialize connection handler + * + * @param array $config List specific configuration from ReservationList.yaml + * + * @return static + * @throws \Exception If Disec connection is not configured properly + */ + public function init(array $config): self + { + try { + $baseUrl = $config['Connection']['base_url']; + if (!str_ends_with($baseUrl, '/')) { + $baseUrl .= '/'; + } + $this->ordersUrl = $baseUrl . 'orders'; + $this->apiKey = $config['Connection']['secret']; + } catch (\Exception $e) { + throw new \Exception('Disec: Invalid configuration'); + } + return $this; + } +} diff --git a/module/Finna/src/Finna/ReservationList/PluginManager.php b/module/Finna/src/Finna/ReservationList/PluginManager.php new file mode 100644 index 00000000000..99d57e42df0 --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/PluginManager.php @@ -0,0 +1,95 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ + +namespace Finna\ReservationList; + +/** + * Reservation list plugin manager + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki + */ +class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager +{ + /** + * Default plugin aliases. + * + * @var array + */ + protected $aliases = [ + 'Disec' => Disec::class, + 'disec' => Disec::class, + 'Database' => Database::class, + 'database' => Database::class, + ]; + + /** + * Default plugin factories. + * + * @var array + */ + protected $factories = [ + Disec::class => ConnectionFactory::class, + Database::class => ConnectionFactory::class, + ]; + + /** + * Constructor + * + * Make sure plugins are properly initialized. + * + * @param mixed $configOrContainerInstance Configuration or container instance + * @param array $v3config If $configOrContainerInstance is a + * container, this value will be passed to the parent constructor. + */ + public function __construct( + $configOrContainerInstance = null, + array $v3config = [] + ) { + // These objects are not meant to be shared -- every time we retrieve one, + // we are building a brand new object. + $this->sharedByDefault = false; + + parent::__construct($configOrContainerInstance, $v3config); + } + + /** + * Return the name of the base class or interface that plug-ins must conform + * to. + * + * @return string + */ + protected function getExpectedInterface() + { + return ConnectionInterface::class; + } +} diff --git a/module/Finna/src/Finna/ReservationList/ReservationListService.php b/module/Finna/src/Finna/ReservationList/ReservationListService.php index 99564d74e7e..a3f5808fd46 100644 --- a/module/Finna/src/Finna/ReservationList/ReservationListService.php +++ b/module/Finna/src/Finna/ReservationList/ReservationListService.php @@ -35,6 +35,7 @@ use Finna\Db\Entity\FinnaResourceListEntityInterface; use Finna\Db\Service\FinnaResourceListResourceServiceInterface; use Finna\Db\Service\FinnaResourceListServiceInterface; +use Laminas\Config\Config; use Laminas\Session\Container; use Laminas\Stdlib\Parameters; use VuFind\Db\Entity\ResourceEntityInterface; @@ -53,6 +54,8 @@ use VuFind\RecordDriver\AbstractBase as RecordDriver; use VuFind\RecordDriver\DefaultRecord; +use function is_string; + /** * Reservation list service * @@ -75,6 +78,24 @@ class ReservationListService implements TranslatorAwareInterface, DbServiceAware */ public const RESOURCE_LIST_TYPE = 'reservationlist'; + /** + * Default values for list config + * + * @var array + */ + protected const RESERVATION_LIST_DEFAULT_VALUES = [ + 'Enabled' => false, + 'Recipient' => [], + 'Datasources' => [], + 'Information' => [], + 'LibraryCardSources' => [], + 'CheckResourceStatus' => false, + 'Connection' => [ + 'type' => 'Database', + ], + 'Identifier' => false, + ]; + /** * Constructor * @@ -88,6 +109,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 */ public function __construct( protected FinnaResourceListServiceInterface $resourceListService, @@ -97,7 +119,8 @@ public function __construct( protected ResourcePopulator $resourcePopulator, protected RecordLoader $recordLoader, protected ?RecordCache $recordCache = null, - protected ?Container $session = null + protected ?Container $session = null, + protected ?array $yamlConfig = [] ) { } @@ -289,6 +312,12 @@ public function setListOrdered( throw new ListPermissionException('list_access_denied'); } $list->setPickupDate(DateTime::createFromFormat('Y-m-d', $request->get('pickup_date')))->setOrdered(); + if ($externalId = $request->get('external_id')) { + $list->setExternalId($externalId); + } + if ($connection = $request->get('connection')) { + $list->setConnection($connection); + } $this->resourceListService->persistEntity($list); } @@ -495,4 +524,69 @@ public function getListsContainingRecord( self::RESOURCE_LIST_TYPE ); } + + /** + * Get list properties defined by institution and list identifier in ReservationList.yaml, + * institution specified information and + * formed translation_keys for the list. + * + * Institution information contains keys and values: + * - name => Example institution name + * - address => Example institution address + * - postal => Example institution postal + * - city => Example institution city + * - email => Example institution email + * + * Translation keys formed: + * - title => list_title_{$institution}_{$listIdentifier}, + * - description => list_description_{$institution}_{$listIdentifier}, + * + * @param string $institution Lists controlling institution + * @param string $listIdentifier List identifier + * + * @return array + */ + public function getListProperties( + string $institution, + string $listIdentifier + ): array { + foreach ($this->yamlConfig['Institutions'][$institution]['Lists'] ?? [] as $list) { + $list = $this->ensureListKeys($list); + if ($list['Identifier'] === $listIdentifier) { + return [ + 'properties' => $list, + 'institution_information' => $this->yamlConfig['Institutions'][$institution]['Information'] ?? [], + 'translation_keys' => [ + 'title' => "ReservationList::list_title_{$institution}_{$listIdentifier}", + 'description' => "ReservationList::list_description_{$institution}_{$listIdentifier}", + ], + ]; + } + } + return [ + 'properties' => self::RESERVATION_LIST_DEFAULT_VALUES, + 'institution_information' => [], + 'translation_keys' => [ + 'title' => '', + 'description' => '', + ], + ]; + } + + /** + * Ensure that lists have all the required keys defined needed in other places. + * Sets the list disabled if list identifier is not set or is not a string. + * + * @param array $list Properties of the list to ensure + * + * @return array + */ + public function ensureListKeys(array $list): array + { + $merged = array_merge(self::RESERVATION_LIST_DEFAULT_VALUES, $list); + if (!is_string($merged['Identifier'])) { + $merged['Enabled'] = false; + } + return $merged; + } } diff --git a/module/Finna/src/Finna/ReservationList/ReservationListServiceFactory.php b/module/Finna/src/Finna/ReservationList/ReservationListServiceFactory.php index 028a6b9caac..3dc6b5d6063 100644 --- a/module/Finna/src/Finna/ReservationList/ReservationListServiceFactory.php +++ b/module/Finna/src/Finna/ReservationList/ReservationListServiceFactory.php @@ -57,6 +57,8 @@ public function __invoke(ContainerInterface $container, $name, array $options = $serviceManager = $container->get(\VuFind\Db\Service\PluginManager::class); $sessionManager = $container->get(\Laminas\Session\SessionManager::class); $session = new \Laminas\Session\Container('ReservationList', $sessionManager); + $reservationListYaml = $container->get(\Finna\Config\YamlReader::class) + ->getFinna('ReservationList.yaml', 'config/finna'); return new ReservationListService( $serviceManager->get(\Finna\Db\Service\FinnaResourceListServiceInterface::class), $serviceManager->get(\Finna\Db\Service\FinnaResourceListResourceServiceInterface::class), @@ -65,7 +67,8 @@ public function __invoke(ContainerInterface $container, $name, array $options = $container->get(\VuFind\Record\ResourcePopulator::class), $container->get(\Finna\Record\Loader::class), $container->get(\VuFind\Record\Cache::class), - $session + $session, + $reservationListYaml ?: [] ); } } diff --git a/module/Finna/src/Finna/View/Helper/Root/ReservationList.php b/module/Finna/src/Finna/View/Helper/Root/ReservationList.php index 857082f839b..b95bcb6b38a 100644 --- a/module/Finna/src/Finna/View/Helper/Root/ReservationList.php +++ b/module/Finna/src/Finna/View/Helper/Root/ReservationList.php @@ -36,7 +36,6 @@ use VuFind\RecordDriver\DefaultRecord; use function in_array; -use function is_string; /** * Reservation list view helper @@ -56,23 +55,6 @@ class ReservationList extends \Laminas\View\Helper\AbstractHelper */ protected ?UserEntityInterface $user; - /** - * Default values for list config - * - * @var array - */ - protected array $requiredFieldsAndDefaultValues = [ - 'Enabled' => false, - 'Recipient' => [], - 'Datasources' => [], - 'Information' => [], - 'LibraryCardSources' => [], - 'Connection' => [ - 'type' => 'Database', - ], - 'Identifier' => false, - ]; - /** * Constructor * @@ -103,20 +85,52 @@ public function __invoke(?UserEntityInterface $user = null): self } /** - * Ensure that lists have all the required keys defined needed in other places. - * Sets the list disabled if list identifier is not set or is not a string. + * Get list properties defined by institution and list identifier in ReservationList.yaml, + * institution specified information and + * formed translation_keys for the list. + * + * Institution information contains keys and values: + * - name => Example institution name + * - address => Example institution address + * - postal => Example institution postal + * - city => Example institution city + * - email => Example institution email + * + * Translation keys formed: + * - title => list_title_{$institution}_{$listIdentifier}, + * - description => list_description_{$institution}_{$listIdentifier}, * - * @param array $list Properties of the list to ensure + * @param string $institution Lists controlling institution + * @param string $listIdentifier List identifier * * @return array */ - protected function ensureListKeys(array $list): array + public function getListProperties( + string $institution, + string $listIdentifier + ): array { + return $this->reservationListService->getListProperties($institution, $listIdentifier); + } + + /** + * Display buttons which routes the request to proper list procedures + * Checks if the list should be displayed for logged-in only users. + * + * @param DefaultRecord $driver Driver to use for checking available lists + * + * @return string + */ + public function renderReserveTemplate(DefaultRecord $driver): string { - $merged = array_merge($this->requiredFieldsAndDefaultValues, $list); - if (!is_string($merged['Identifier'])) { - $merged['Enabled'] = false; + if (!$this->isFunctionalityEnabled()) { + return ''; } - return $merged; + // Collect lists where we could potentially save this: + $lists = $this->getAvailableListsForRecord($driver); + + // Set up the needed context in the view: + $view = $this->getView(); + return $view->render('Helpers/reservationlist-reserve.phtml', compact('lists', 'driver')); } /** @@ -126,7 +140,7 @@ protected function ensureListKeys(array $list): array * * @return array */ - protected function getAvailableListsForRecord(DefaultRecord $driver): array + public function getAvailableListsForRecord(DefaultRecord $driver): array { $datasource = $driver->tryMethod('getDatasource'); if (!$datasource) { @@ -136,7 +150,7 @@ protected function getAvailableListsForRecord(DefaultRecord $driver): array foreach ($this->yamlConfig['Institutions'] ?? [] as $institution => $settings) { $current = [$institution => []]; foreach ($settings['Lists'] ?? [] as $list) { - $list = $this->ensureListKeys($list); + $list = $this->reservationListService->ensureListKeys($list); if ( $list['Enabled'] && in_array($datasource, $list['Datasources']) @@ -153,54 +167,6 @@ protected function getAvailableListsForRecord(DefaultRecord $driver): array return $result; } - /** - * Get list properties defined by institution and list identifier in ReservationList.yaml, - * institution specified information and - * formed translation_keys for the list. - * - * Institution information contains keys and values: - * - name => Example institution name - * - address => Example institution address - * - postal => Example institution postal - * - city => Example institution city - * - email => Example institution email - * - * Translation keys formed: - * - title => list_title_{$institution}_{$listIdentifier}, - * - description => list_description_{$institution}_{$listIdentifier}, - * - * @param string $institution Lists controlling institution - * @param string $listIdentifier List identifier - * - * @return array - */ - public function getListProperties( - string $institution, - string $listIdentifier - ): array { - foreach ($this->yamlConfig['Institutions'][$institution]['Lists'] ?? [] as $list) { - $list = $this->ensureListKeys($list); - if ($list['Identifier'] === $listIdentifier) { - return [ - 'properties' => $list, - 'institution_information' => $this->yamlConfig['Institutions'][$institution]['Information'] ?? [], - 'translation_keys' => [ - 'title' => "ReservationList::list_title_{$institution}_{$listIdentifier}", - 'description' => "ReservationList::list_description_{$institution}_{$listIdentifier}", - ], - ]; - } - } - return [ - 'properties' => $this->requiredFieldsAndDefaultValues, - 'institution_information' => [], - 'translation_keys' => [ - 'title' => '', - 'description' => '', - ], - ]; - } - /** * Check if the user has proper requirements to order records. * Function checks if there is required LibraryCardSources @@ -223,27 +189,6 @@ public function checkUserRightsForList(array $list): bool return in_array($patron['source'], $list['LibraryCardSources']); } - /** - * Display buttons which routes the request to proper list procedures - * Checks if the list should be displayed for logged-in only users. - * - * @param DefaultRecord $driver Driver to use for checking available lists - * - * @return string - */ - public function renderReserveTemplate(DefaultRecord $driver): string - { - if (!$this->isFunctionalityEnabled()) { - return ''; - } - // Collect lists where we could potentially save this: - $lists = $this->getAvailableListsForRecord($driver); - - // Set up the needed context in the view: - $view = $this->getView(); - return $view->render('Helpers/reservationlist-reserve.phtml', compact('lists', 'driver')); - } - /** * Get available reservation lists for user, user must be invoked * diff --git a/themes/finna2/js/finna-reservation-list.js b/themes/finna2/js/finna-reservation-list.js new file mode 100644 index 00000000000..51fcd2c8dff --- /dev/null +++ b/themes/finna2/js/finna-reservation-list.js @@ -0,0 +1,31 @@ +/*global VuFind, finna */ +finna.reservationList = (function finnaReservationList() { + /** + * Check status of given list + * @param {HTMLElement} element Element where status is inserted + */ + function checkStatus(element) { + const queryParams = new URLSearchParams({method: 'reservationList', list_id: element.dataset.listId, type: 'status'}); + fetch (`${VuFind.path}/AJAX/JSON?${queryParams.toString()}`) + .then(response => { + if (!response.ok) { + throw new Error(VuFind.translate('error_occurred')); + } + return response.json(); + }) + .then(responseJSON => { + element.innerText = responseJSON.data; + element.classList.remove('pending'); + }); + } + + var my = { + init: () => { + document.querySelectorAll('.js-reservation-list-status').forEach(el => { + checkStatus(el); + }); + } + }; + + return my; +})(); diff --git a/themes/finna2/js/finna.js b/themes/finna2/js/finna.js index 380dd3b7972..5ab6a4c2dba 100644 --- a/themes/finna2/js/finna.js +++ b/themes/finna2/js/finna.js @@ -44,6 +44,7 @@ var finna = (function finnaModule() { 'mdEditable', 'a11y', 'finnaDatepicker', + 'reservationList', ]; $.each(modules, function initModule(ind, module) { diff --git a/themes/finna2/less/finna/reservationlist.less b/themes/finna2/less/finna/reservationlist.less index d93edc79a67..fceecac8494 100644 --- a/themes/finna2/less/finna/reservationlist.less +++ b/themes/finna2/less/finna/reservationlist.less @@ -12,6 +12,9 @@ p { margin: 0; } + &.js-reservation-list-status.pending { + display: none; + } } .list-controls { margin-top: 10px; diff --git a/themes/finna2/scss/finna/reservationlist.scss b/themes/finna2/scss/finna/reservationlist.scss index 54359f89131..225c88feaeb 100644 --- a/themes/finna2/scss/finna/reservationlist.scss +++ b/themes/finna2/scss/finna/reservationlist.scss @@ -12,6 +12,9 @@ p { margin: 0; } + &.js-reservation-list-status.pending { + display: none; + } } .list-controls { margin-top: 10px; diff --git a/themes/finna2/templates/reservationlist/displaylist.phtml b/themes/finna2/templates/reservationlist/displaylist.phtml index 2362ac86594..66d51974e4e 100644 --- a/themes/finna2/templates/reservationlist/displaylist.phtml +++ b/themes/finna2/templates/reservationlist/displaylist.phtml @@ -57,6 +57,10 @@

transEsc('ReservationList::list_pickup_date', ['%%date%%' => $this->list->getPickupDate()->format('d.m.Y')]) ?>

+ list->getOrdered() && $this->list->getExternalId()): ?> +
+
+
list->getOrdered() && $this->results->getResults() && $listProperties['properties']['Enabled']): ?> diff --git a/themes/finna2/theme.config.php b/themes/finna2/theme.config.php index 3996aebc4fe..a10f9032ba4 100644 --- a/themes/finna2/theme.config.php +++ b/themes/finna2/theme.config.php @@ -266,6 +266,7 @@ 'finna-select-a11y.js', 'finna-a11y.js', 'finna-datepicker.js', + 'finna-reservation-list.js', 'components/finna-bazaar-browse-bar.js', 'components/finna-md-editable.js', 'components/finna-tabs-nav.js', From a8a59ae23e418fbb5ba10d8ad8410476c035dfa8 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:57:26 +0200 Subject: [PATCH 02/15] Adjusted to log values, added ReservationListStatus enumerator --- .../config/finna/ReservationList.yaml.sample | 9 ++- .../languages/finna/ReservationList/en-gb.ini | 12 ++++ local/languages/finna/ReservationList/fi.ini | 12 ++++ local/languages/finna/ReservationList/se.ini | 12 ++++ local/languages/finna/ReservationList/sv.ini | 12 ++++ .../src/Finna/AjaxHandler/ReservationList.php | 2 +- .../Controller/ReservationListController.php | 6 +- .../Finna/ReservationList/AbstractBase.php | 17 ++--- .../Finna/src/Finna/ReservationList/Disec.php | 55 ++++++++++------ .../Finna/ReservationList/PluginManager.php | 12 ++-- .../ReservationList/ReservationListStatus.php | 63 +++++++++++++++++++ 11 files changed, 169 insertions(+), 43 deletions(-) create mode 100644 module/Finna/src/Finna/ReservationList/ReservationListStatus.php diff --git a/local/config/finna/ReservationList.yaml.sample b/local/config/finna/ReservationList.yaml.sample index 80cbdc73afc..73803159b32 100644 --- a/local/config/finna/ReservationList.yaml.sample +++ b/local/config/finna/ReservationList.yaml.sample @@ -9,8 +9,13 @@ # List can contain same information as under institution information to be more specific # about where the order is being delivered # LibraryCardSources is used to check for active connection to ILS to be able to use lists -# Connection holds information about type of lists, currently only value supported is type: Database -# and is the default value, if omitted +# Connection holds information about type of lists: +# Database: Default connection, orders handled with sending forms +# handler: email [Optional] Default handler email, other values found in FeedbackForms.yaml primary handlers +# Disec: +# base_url: Api base url +# secret: Api specific secret +# use_cat_id: [Optional] Use catalog id for user instead of firstName, lastName, email. Default false. # # Each list declared uses their own translation keys under translation domain ReservationList:: # diff --git a/local/languages/finna/ReservationList/en-gb.ini b/local/languages/finna/ReservationList/en-gb.ini index 367d6a55b3e..58d4d274065 100644 --- a/local/languages/finna/ReservationList/en-gb.ini +++ b/local/languages/finna/ReservationList/en-gb.ini @@ -28,3 +28,15 @@ Reservation List Name = "Reservation lists name" Send Reservation Request = "Send reservation request" select_desired_contact_method = "Select desired contact method" Select = "Select" + +; List statuses: +status_unknown = "" +status_in_process = "In process" +status_handled = "Handled" +status_delivered = "Delivered" +status_cancelled = "Canceled" +status_replied = "Replied" +status_removed_item = "Item removed" +status_loaned = "Loaned" +status_returned = "Returned" +status_renewed = "Renewed" diff --git a/local/languages/finna/ReservationList/fi.ini b/local/languages/finna/ReservationList/fi.ini index 17335babf8f..12303088157 100644 --- a/local/languages/finna/ReservationList/fi.ini +++ b/local/languages/finna/ReservationList/fi.ini @@ -28,3 +28,15 @@ Reservation List Name = "Varauslistan nimi" Send Reservation Request = "Lähetä varauspyyntö" select_desired_contact_method = "Valitse haluamasi yhteydenottotapa" Select = "Valitse" + +; List statuses: +status_unknown = "" +status_in_process = "Käsittelyssä" +status_handled = "Käsitelty" +status_delivered = "Toimitettu" +status_cancelled = "Peruutettu" +status_replied = "Vastattu" +status_removed_item = "Aineisto poistettu" +status_loaned = "Lainattu" +status_returned = "Palautettu" +status_renewed = "Uusittu" diff --git a/local/languages/finna/ReservationList/se.ini b/local/languages/finna/ReservationList/se.ini index 9a2a2d90098..f6b88851078 100644 --- a/local/languages/finna/ReservationList/se.ini +++ b/local/languages/finna/ReservationList/se.ini @@ -28,3 +28,15 @@ Reservation List Name = "" Send Reservation Request = "" select_desired_contact_method = "" Select = "" + +; List statuses: +status_unknown = "" +status_in_process = "" +status_handled = "" +status_delivered = "" +status_cancelled = "" +status_replied = "" +status_removed_item = "" +status_loaned = "" +status_returned = "" +status_renewed = "" diff --git a/local/languages/finna/ReservationList/sv.ini b/local/languages/finna/ReservationList/sv.ini index 70c81aa8a42..65dff0dc389 100644 --- a/local/languages/finna/ReservationList/sv.ini +++ b/local/languages/finna/ReservationList/sv.ini @@ -28,3 +28,15 @@ Reservation List Name = "Namn för bokningslista" Send Reservation Request = "Skicka bokningsförfrågan" select_desired_contact_method = "Välj önskad kontaktmetod" Select = "Välj" + +; List statuses: +status_unknown = "" +status_in_process = "Behandlas" +status_handled = "Behandlade" +status_delivered = "Levererad" +status_cancelled = "Annulerad" +status_replied = "Besvarad" +status_removed_item = "Objekt borttaget" +status_loaned = "Lånad" +status_returned = "Returnerad" +status_renewed = "Förnyad" diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationList.php b/module/Finna/src/Finna/AjaxHandler/ReservationList.php index 56fdf6009d9..31bb10f9457 100644 --- a/module/Finna/src/Finna/AjaxHandler/ReservationList.php +++ b/module/Finna/src/Finna/AjaxHandler/ReservationList.php @@ -102,7 +102,7 @@ public function handleRequest(Params $params) $handler = $this->connectionHandler->get($connectionType); $handler->init($listProperties['properties']); $result = $handler->getListStatus($list, $this->user); - $result = $this->translate(['ReservationList', 'status_' . $result]); + $result = $this->translate($result); break; default: break; diff --git a/module/Finna/src/Finna/Controller/ReservationListController.php b/module/Finna/src/Finna/Controller/ReservationListController.php index 58c62a6e2d4..c1f87ec6cf7 100644 --- a/module/Finna/src/Finna/Controller/ReservationListController.php +++ b/module/Finna/src/Finna/Controller/ReservationListController.php @@ -333,9 +333,9 @@ public function placeOrderAction() if (!$this->formWasSubmitted(useCaptcha: false)) { $form->setData( [ - 'firstName' => $user->getFirstname(), - 'lastName' => $user->getLastname(), - 'email' => $user->getEmail(), + 'firstName' => $user->getFirstname(), + 'lastName' => $user->getLastname(), + 'email' => $user->getEmail(), ] ); return $view; diff --git a/module/Finna/src/Finna/ReservationList/AbstractBase.php b/module/Finna/src/Finna/ReservationList/AbstractBase.php index ea5bade553c..6a25219a17a 100644 --- a/module/Finna/src/Finna/ReservationList/AbstractBase.php +++ b/module/Finna/src/Finna/ReservationList/AbstractBase.php @@ -45,17 +45,11 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org Main Site */ -class AbstractBase implements ConnectionInterface +class AbstractBase implements ConnectionInterface, \Laminas\Log\LoggerAwareInterface { + use \VuFind\Log\LoggerAwareTrait; use GetServiceTrait; - /** - * Default unknown status - * - * @var string - */ - public const STATUS_UNKNOWN = 'UNKNOWN'; - /** * Recipients for email handler defined in ReservationList.yaml * @@ -95,8 +89,8 @@ public function placeOrder(Params $params, UserEntityInterface $user, Form $form $formPluginManager = $this->getService(\VuFind\Form\Handler\PluginManager::class); $result = $formPluginManager->get($this->configuredHandler)->handle($form, $params, $user); return [ - 'success' => $result, - 'external_id' => null, + 'success' => $result, + 'external_id' => null, ]; } @@ -110,7 +104,8 @@ public function placeOrder(Params $params, UserEntityInterface $user, Form $form */ public function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string { - return self::STATUS_UNKNOWN; + $status = ReservationListStatus::UNKNOWN; + return $status->getTranslationKey(); } /** diff --git a/module/Finna/src/Finna/ReservationList/Disec.php b/module/Finna/src/Finna/ReservationList/Disec.php index b6ea2ac32de..79d30e5d26f 100644 --- a/module/Finna/src/Finna/ReservationList/Disec.php +++ b/module/Finna/src/Finna/ReservationList/Disec.php @@ -59,6 +59,13 @@ class Disec extends AbstractBase */ protected $apiKey; + /** + * Use catalog id to send user data instead of users first and last name + * + * @param bool + */ + protected bool $useCatId = false; + /** * Places an order * @@ -77,9 +84,9 @@ public function placeOrder(Params $params, UserEntityInterface $user, Form $form $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($this->ordersUrl); $client->setHeaders( [ - 'Content-Type: application/json', - 'accept: */*', - 'X-API-Key: ' . $this->apiKey, + 'Content-Type: application/json', + 'accept: */*', + 'X-API-Key: ' . $this->apiKey, ] ); $client->setMethod(\Laminas\Http\Request::METHOD_POST); @@ -92,17 +99,21 @@ public function placeOrder(Params $params, UserEntityInterface $user, Form $form } } $data = [ - 'resourceIds' => $resources, - 'customer' => [ - 'firstName' => $params->fromPost('firstName') ?? $user->getFirstname(), - 'lastName' => $params->fromPost('lastName') ?? $user->getLastname(), - 'email' => $params->fromPost('email') ?? $user->getEmail(), - ], - 'contentInfo' => $params->fromPost('message', '') . PHP_EOL, + 'resourceIds' => $resources, + 'customer' => [ + 'firstName' => $params->fromPost('firstName') ?? $user->getFirstname(), + 'lastName' => $params->fromPost('lastName') ?? $user->getLastname(), + 'email' => $params->fromPost('email') ?? $user->getEmail(), + ], + 'contentInfo' => $params->fromPost('message', '') . PHP_EOL, ]; $data['contentInfo'] .= $params->fromPost('pickup_date', '') . PHP_EOL; if ($catId = $user->getCatId()) { [, $id] = explode('.', $catId); + if ($this->useCatId) { + $data['kohaId'] = (int)$id; + unset($data['customer']); + } $data['contentInfo'] .= 'cat_id: ' . $id; } $client->setRawBody(json_encode($data)); @@ -111,13 +122,14 @@ public function placeOrder(Params $params, UserEntityInterface $user, Form $form if ($response->isSuccess()) { $body = json_decode($response->getBody(), true); return [ - 'success' => true, - 'external_id' => $body['id'], + 'success' => true, + 'external_id' => $body['id'], ]; } + $this->debug('Disec: failed to place order: ' . $response->getBody()); return [ - 'success' => false, - 'external_id' => null, + 'success' => false, + 'external_id' => null, ]; } @@ -136,19 +148,21 @@ public function getListStatus(FinnaResourceListEntityInterface $list, UserEntity $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($formedUrl); $client->setHeaders( [ - 'Content-Type: application/json', - 'accept: */*', - 'X-API-Key: ' . $this->apiKey, + 'Content-Type: application/json', + 'accept: */*', + 'X-API-Key: ' . $this->apiKey, ] ); $client->setMethod(\Laminas\Http\Request::METHOD_GET); $response = $client->send(); - + $status = ReservationListStatus::UNKNOWN; if ($response->isSuccess()) { $body = json_decode($response->getBody(), true); - return $body['status'] ?? self::STATUS_UNKNOWN; + $status = ReservationListStatus::tryFrom(mb_strtolower($body['status'])) ?? ReservationListStatus::UNKNOWN; + } else { + $this->debug('Disec: failed to fetch status for list: ' . $response->getBody()); } - return self::STATUS_UNKNOWN; + return $status->getTranslationKey(); } /** @@ -168,6 +182,7 @@ public function init(array $config): self } $this->ordersUrl = $baseUrl . 'orders'; $this->apiKey = $config['Connection']['secret']; + $this->useCatId = $config['Connection']['use_cat_id'] ?? false; } catch (\Exception $e) { throw new \Exception('Disec: Invalid configuration'); } diff --git a/module/Finna/src/Finna/ReservationList/PluginManager.php b/module/Finna/src/Finna/ReservationList/PluginManager.php index 99d57e42df0..fce9d1ee0fc 100644 --- a/module/Finna/src/Finna/ReservationList/PluginManager.php +++ b/module/Finna/src/Finna/ReservationList/PluginManager.php @@ -46,10 +46,10 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $aliases = [ - 'Disec' => Disec::class, - 'disec' => Disec::class, - 'Database' => Database::class, - 'database' => Database::class, + 'Disec' => Disec::class, + 'disec' => Disec::class, + 'Database' => Database::class, + 'database' => Database::class, ]; /** @@ -58,8 +58,8 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - Disec::class => ConnectionFactory::class, - Database::class => ConnectionFactory::class, + Disec::class => ConnectionFactory::class, + Database::class => ConnectionFactory::class, ]; /** diff --git a/module/Finna/src/Finna/ReservationList/ReservationListStatus.php b/module/Finna/src/Finna/ReservationList/ReservationListStatus.php new file mode 100644 index 00000000000..9ea9e588caf --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/ReservationListStatus.php @@ -0,0 +1,63 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ + +namespace Finna\ReservationList; + +/** + * Reservation list status enum. + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +enum ReservationListStatus: string +{ + case UNKNOWN = 'unknown'; + case IN_PROCESS = 'in_process'; + case HANDLED = 'handled'; + case DELIVERED = 'delivered'; + case CANCELLED = 'cancelled'; + case REPLIED = 'replied'; + case REMOVED_ITEM = 'removed_item'; + case LOANED = 'loaned'; + case RETURNED = 'returned'; + case RENEWED = 'renewed'; + + /** + * Return a translation key representing the status. + * + * @return string + */ + public function getTranslationKey(): string + { + return 'ReservationList::status_' . $this->value; + } +} From 412e76bca46f6da7e51afeb12c1649896ad1751e Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:56:36 +0200 Subject: [PATCH 03/15] Review fixes --- .../config/finna/ReservationList.yaml.sample | 4 +- .../languages/finna/ReservationList/en-gb.ini | 5 +- local/languages/finna/ReservationList/fi.ini | 5 +- local/languages/finna/ReservationList/sv.ini | 5 +- module/Finna/sql/mysql.sql | 4 +- .../src/Finna/AjaxHandler/ReservationList.php | 6 +- .../Controller/ReservationListController.php | 26 ++++-- .../Finna/ReservationList/AbstractBase.php | 24 ++--- .../ReservationList/ConnectionFactory.php | 4 +- .../ReservationList/ConnectionInterface.php | 8 +- .../src/Finna/ReservationList/Database.php | 43 --------- .../Finna/src/Finna/ReservationList/Disec.php | 56 ++++++------ .../Finna/ReservationList/FeedbackForm.php | 89 +++++++++++++++++++ .../Finna/ReservationList/PluginManager.php | 6 +- .../ReservationListService.php | 14 +-- .../ReservationList/ReservationListStatus.php | 23 ++++- themes/finna2/js/finna-reservation-list.js | 6 +- 17 files changed, 202 insertions(+), 126 deletions(-) delete mode 100644 module/Finna/src/Finna/ReservationList/Database.php create mode 100644 module/Finna/src/Finna/ReservationList/FeedbackForm.php diff --git a/local/config/finna/ReservationList.yaml.sample b/local/config/finna/ReservationList.yaml.sample index 73803159b32..b6a2028eb0c 100644 --- a/local/config/finna/ReservationList.yaml.sample +++ b/local/config/finna/ReservationList.yaml.sample @@ -10,7 +10,7 @@ # about where the order is being delivered # LibraryCardSources is used to check for active connection to ILS to be able to use lists # Connection holds information about type of lists: -# Database: Default connection, orders handled with sending forms +# FeedbackForm: Default connection, orders handled with sending forms # handler: email [Optional] Default handler email, other values found in FeedbackForms.yaml primary handlers # Disec: # base_url: Api base url @@ -51,4 +51,4 @@ Institutions: LibraryCardSources: - connection_established_to_use_lists Connection: - type: Database + type: FeedbackForm diff --git a/local/languages/finna/ReservationList/en-gb.ini b/local/languages/finna/ReservationList/en-gb.ini index 58d4d274065..3b533375ed8 100644 --- a/local/languages/finna/ReservationList/en-gb.ini +++ b/local/languages/finna/ReservationList/en-gb.ini @@ -32,11 +32,12 @@ Select = "Select" ; List statuses: status_unknown = "" status_in_process = "In process" -status_handled = "Handled" +status_processed = "Handled" status_delivered = "Delivered" status_cancelled = "Canceled" status_replied = "Replied" status_removed_item = "Item removed" -status_loaned = "Loaned" +status_on_loan = "Loaned" status_returned = "Returned" status_renewed = "Renewed" +status_pending = "Pending" diff --git a/local/languages/finna/ReservationList/fi.ini b/local/languages/finna/ReservationList/fi.ini index 12303088157..9628c5def87 100644 --- a/local/languages/finna/ReservationList/fi.ini +++ b/local/languages/finna/ReservationList/fi.ini @@ -32,11 +32,12 @@ Select = "Valitse" ; List statuses: status_unknown = "" status_in_process = "Käsittelyssä" -status_handled = "Käsitelty" +status_processed = "Käsitelty" status_delivered = "Toimitettu" status_cancelled = "Peruutettu" status_replied = "Vastattu" status_removed_item = "Aineisto poistettu" -status_loaned = "Lainattu" +status_on_loan = "Lainassa" status_returned = "Palautettu" status_renewed = "Uusittu" +status_pending = "Odottaa" diff --git a/local/languages/finna/ReservationList/sv.ini b/local/languages/finna/ReservationList/sv.ini index 65dff0dc389..39bc1c23f26 100644 --- a/local/languages/finna/ReservationList/sv.ini +++ b/local/languages/finna/ReservationList/sv.ini @@ -32,11 +32,12 @@ Select = "Välj" ; List statuses: status_unknown = "" status_in_process = "Behandlas" -status_handled = "Behandlade" +status_processed = "Behandlad" status_delivered = "Levererad" status_cancelled = "Annulerad" status_replied = "Besvarad" status_removed_item = "Objekt borttaget" -status_loaned = "Lånad" +status_on_loan = "Lånad" status_returned = "Returnerad" status_renewed = "Förnyad" +status_pending = "Väntar" diff --git a/module/Finna/sql/mysql.sql b/module/Finna/sql/mysql.sql index debb3de2983..7983930e6a6 100644 --- a/module/Finna/sql/mysql.sql +++ b/module/Finna/sql/mysql.sql @@ -340,8 +340,8 @@ CREATE TABLE `finna_resource_list` ( `list_type` varchar(200) NOT NULL DEFAULT 'resourcelist', `ordered` datetime DEFAULT NULL, `pickup_date` datetime DEFAULT NULL, - `connection` varchar(40) NOT NULL DEFAULT 'database', - `external_id` varchar(40) DEFAULT NULL, + `connection` varchar(40) NOT NULL DEFAULT 'feedbackform', + `external_id` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), CONSTRAINT `resource_list_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationList.php b/module/Finna/src/Finna/AjaxHandler/ReservationList.php index 31bb10f9457..43c08a4f0cd 100644 --- a/module/Finna/src/Finna/AjaxHandler/ReservationList.php +++ b/module/Finna/src/Finna/AjaxHandler/ReservationList.php @@ -91,7 +91,7 @@ public function handleRequest(Params $params) self::STATUS_HTTP_BAD_REQUEST ); } - $result = ''; + $result = []; switch ($params->fromQuery('type')) { case 'status': $listProperties = $this->reservationListService->getListProperties( @@ -101,8 +101,8 @@ public function handleRequest(Params $params) $connectionType = $list->getConnection(); $handler = $this->connectionHandler->get($connectionType); $handler->init($listProperties['properties']); - $result = $handler->getListStatus($list, $this->user); - $result = $this->translate($result); + $response = $handler->getListStatus($list, $this->user); + $result['status'] = $this->translate($response); break; default: break; diff --git a/module/Finna/src/Finna/Controller/ReservationListController.php b/module/Finna/src/Finna/Controller/ReservationListController.php index c1f87ec6cf7..9d8544388b0 100644 --- a/module/Finna/src/Finna/Controller/ReservationListController.php +++ b/module/Finna/src/Finna/Controller/ReservationListController.php @@ -310,8 +310,9 @@ public function placeOrderAction() $resourcesText .= $resource->getRecordId() . '||' . $resource->getTitle() . PHP_EOL; $resourceIds[] = $resource->getSource() . '|' . $resource->getRecordId(); } + $postRequest = $request->getPost(); // Set reservationlist specific form values - $request->getPost() + $postRequest ->set('rl_list_id', $listId) ->set('rl_institution', $list->getInstitution()) ->set('rl_list_identifier', $list->getListConfigIdentifier()) @@ -319,7 +320,7 @@ public function placeOrderAction() ->set('resourceIDs', $resourceIds); $form = $this->getService(\Finna\Form\Form::class); - $form->setFormId(formId: $formId, prefill: $request->getPost()->toArray()); + $form->setFormId(formId: $formId, prefill: $postRequest->toArray()); if (!$form->isEnabled()) { throw new \VuFind\Exception\Forbidden("Form '$formId' is disabled"); @@ -347,10 +348,25 @@ public function placeOrderAction() $connectionType = $listProperties['Connection']['type']; $handler = $this->getService(\Finna\ReservationList\PluginManager::class)->get($connectionType); $handler->init($listProperties); - $result = $handler->placeOrder($this->params(), $user, $form); + $gatheredPostValues = [ + 'firstName' => $postRequest->get('firstName'), + 'lastName' => $postRequest->get('lastName'), + 'email' => $postRequest->get('email'), + 'record_ids' => $postRequest->get('record_ids'), + 'phone' => $postRequest->get('phone'), + 'message' => $postRequest->get('message'), + 'pickup_date' => $postRequest->get('pickup_date'), + 'resourceIDs' => $postRequest->get('resourceIDs'), + ]; + if ($handler instanceof \Finna\ReservationList\FeedbackForm) { + $result = $handler->placeOrder($this->params(), $user, $form); + } else { + $result = $handler->placeOrder($gatheredPostValues, $user, $form); + } if ($result['success']) { - $request->getPost()->set('external_id', $result['external_id'])->set('connection', $connectionType); - $this->reservationListService->setListOrdered($user, $list, $request->getPost()); + $gatheredPostValues['external_id'] = $result['external_id']; + $gatheredPostValues['connection'] = $connectionType; + $this->reservationListService->setListOrdered($user, $list, $gatheredPostValues); $this->flashMessenger()->addSuccessMessage($form->getSubmitResponse()); return $this->getRefreshResponse(); } else { diff --git a/module/Finna/src/Finna/ReservationList/AbstractBase.php b/module/Finna/src/Finna/ReservationList/AbstractBase.php index 6a25219a17a..1b9aeed6ea4 100644 --- a/module/Finna/src/Finna/ReservationList/AbstractBase.php +++ b/module/Finna/src/Finna/ReservationList/AbstractBase.php @@ -1,7 +1,7 @@ getController()->getRequest()->getPost()->set('recipient', $this->recipients); - $formPluginManager = $this->getService(\VuFind\Form\Handler\PluginManager::class); - $result = $formPluginManager->get($this->configuredHandler)->handle($form, $params, $user); return [ - 'success' => $result, + 'success' => false, 'external_id' => null, ]; } @@ -114,16 +111,9 @@ public function getListStatus(FinnaResourceListEntityInterface $list, UserEntity * @param array $config List specific configuration from ReservationList.yaml * * @return static - * @throws \Exception If Database connection is not configured properly */ public function init(array $config): self { - try { - $this->recipients = $config['Recipient']; - $this->configuredHandler = $config['Connection']['handler'] ?? 'email'; - } catch (\Exception $e) { - throw new \Exception('Database: Invalid configuration'); - } return $this; } } diff --git a/module/Finna/src/Finna/ReservationList/ConnectionFactory.php b/module/Finna/src/Finna/ReservationList/ConnectionFactory.php index b93bb4db4bf..a31aae5146b 100644 --- a/module/Finna/src/Finna/ReservationList/ConnectionFactory.php +++ b/module/Finna/src/Finna/ReservationList/ConnectionFactory.php @@ -1,7 +1,7 @@ - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org/wiki/development:plugins:controllers Wiki - */ - -namespace Finna\ReservationList; - -/** - * Database connection handler - * - * @category VuFind - * @package ReservationList - * @author Juha Luoma - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link http://vufind.org Main Site - */ -class Database extends AbstractBase -{ -} diff --git a/module/Finna/src/Finna/ReservationList/Disec.php b/module/Finna/src/Finna/ReservationList/Disec.php index 79d30e5d26f..73d894c146a 100644 --- a/module/Finna/src/Finna/ReservationList/Disec.php +++ b/module/Finna/src/Finna/ReservationList/Disec.php @@ -34,6 +34,8 @@ use VuFind\Db\Entity\UserEntityInterface; use VuFind\Form\Form; +use function is_array; + /** * Disec connection handler * @@ -66,34 +68,38 @@ class Disec extends AbstractBase */ protected bool $useCatId = false; + /** + * Common headers in requests + * + * @var array + */ + protected array $requestHeaders = [ + 'Content-Type: application/json', + 'accept: */*', + ]; + /** * Places an order * - * @param Params $params Parameters containing data from posting place order form - * @param UserEntityInterface $user User entity - * @param Form $form Form posted when submitting the order + * @param array|Params $postValues Key value pairs of post parameters to send or params plugin + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order * * @return array [external_id: Id in external service or null, success: true or false] */ - public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array + public function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array { - if (!$this->ordersUrl) { - throw new \Exception('Invalid configuration.'); + if (!is_array($postValues)) { + throw new \Exception('ReservationList Disec: Illegal parameter type.'); } $data = []; $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($this->ordersUrl); - $client->setHeaders( - [ - 'Content-Type: application/json', - 'accept: */*', - 'X-API-Key: ' . $this->apiKey, - ] - ); + $client->setHeaders($this->requestHeaders); $client->setMethod(\Laminas\Http\Request::METHOD_POST); $resources = []; $recordLoader = $this->getService(\VuFind\Record\Loader::class); - foreach ($recordLoader->loadBatch($params->fromPost('resourceIDs', [])) as $record) { + foreach ($recordLoader->loadBatch($postValues['resourceIDs']) as $record) { if ($identifiers = $record->tryMethod('getIdentifier', [])) { $resources[] = array_shift($identifiers); } @@ -101,13 +107,13 @@ public function placeOrder(Params $params, UserEntityInterface $user, Form $form $data = [ 'resourceIds' => $resources, 'customer' => [ - 'firstName' => $params->fromPost('firstName') ?? $user->getFirstname(), - 'lastName' => $params->fromPost('lastName') ?? $user->getLastname(), - 'email' => $params->fromPost('email') ?? $user->getEmail(), + 'firstName' => $postValues['firstName'], + 'lastName' => $postValues['lastName'], + 'email' => $postValues['email'], ], - 'contentInfo' => $params->fromPost('message', '') . PHP_EOL, + 'contentInfo' => $postValues['message'] . PHP_EOL, ]; - $data['contentInfo'] .= $params->fromPost('pickup_date', '') . PHP_EOL; + $data['contentInfo'] .= $postValues['pickup_date'] . PHP_EOL; if ($catId = $user->getCatId()) { [, $id] = explode('.', $catId); if ($this->useCatId) { @@ -146,19 +152,13 @@ public function getListStatus(FinnaResourceListEntityInterface $list, UserEntity $externalId = $list->getExternalId(); $formedUrl = implode('/', [$this->ordersUrl, $externalId]); $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($formedUrl); - $client->setHeaders( - [ - 'Content-Type: application/json', - 'accept: */*', - 'X-API-Key: ' . $this->apiKey, - ] - ); + $client->setHeaders($this->requestHeaders); $client->setMethod(\Laminas\Http\Request::METHOD_GET); $response = $client->send(); $status = ReservationListStatus::UNKNOWN; if ($response->isSuccess()) { $body = json_decode($response->getBody(), true); - $status = ReservationListStatus::tryFrom(mb_strtolower($body['status'])) ?? ReservationListStatus::UNKNOWN; + $status = ReservationListStatus::mapEnumFromString($body['status'] ?? ''); } else { $this->debug('Disec: failed to fetch status for list: ' . $response->getBody()); } @@ -181,7 +181,7 @@ public function init(array $config): self $baseUrl .= '/'; } $this->ordersUrl = $baseUrl . 'orders'; - $this->apiKey = $config['Connection']['secret']; + $this->requestHeaders[] = 'X-API-Key: ' . $config['Connection']['secret']; $this->useCatId = $config['Connection']['use_cat_id'] ?? false; } catch (\Exception $e) { throw new \Exception('Disec: Invalid configuration'); diff --git a/module/Finna/src/Finna/ReservationList/FeedbackForm.php b/module/Finna/src/Finna/ReservationList/FeedbackForm.php new file mode 100644 index 00000000000..d88edfd4b9a --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/FeedbackForm.php @@ -0,0 +1,89 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ + +namespace Finna\ReservationList; + +use Exception; +use Laminas\Mvc\Controller\Plugin\Params; +use VuFind\Db\Entity\UserEntityInterface; +use VuFind\Form\Form; + +/** + * FeedbackForm connection handler + * + * @category VuFind + * @package ReservationList + * @author Juha Luoma + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +class FeedbackForm extends AbstractBase +{ + /** + * Places an order + * + * @param array|Params $postValues Key value pairs of post parameters to send or params plugin + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order + * + * @return array [external_id: Id in external service or null, success: true or false] + */ + public function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array + { + if (!($postValues instanceof Params)) { + throw new Exception('ReservationList FeedbackForm: Illegal parameter type.'); + } + $postValues->getController()->getRequest()->getPost()->set('recipient', $this->recipients); + $result = $this->getService(\VuFind\Form\Handler\PluginManager::class) + ->get($this->configuredHandler)->handle($form, $postValues, $user); + return [ + 'success' => $result, + 'external_id' => null, + ]; + } + + /** + * Initialize connection handler + * + * @param array $config List specific configuration from ReservationList.yaml + * + * @return static + * @throws \Exception If Database connection is not configured properly + */ + public function init(array $config): self + { + try { + $this->recipients = $config['Recipient']; + $this->configuredHandler = $config['Connection']['handler'] ?? 'email'; + } catch (\Exception $e) { + throw new \Exception('Database: Invalid configuration'); + } + return $this; + } +} diff --git a/module/Finna/src/Finna/ReservationList/PluginManager.php b/module/Finna/src/Finna/ReservationList/PluginManager.php index fce9d1ee0fc..af260671703 100644 --- a/module/Finna/src/Finna/ReservationList/PluginManager.php +++ b/module/Finna/src/Finna/ReservationList/PluginManager.php @@ -48,8 +48,8 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager protected $aliases = [ 'Disec' => Disec::class, 'disec' => Disec::class, - 'Database' => Database::class, - 'database' => Database::class, + 'FeedbackForm' => FeedbackForm::class, + 'feedbackform' => FeedbackForm::class, ]; /** @@ -59,7 +59,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager */ protected $factories = [ Disec::class => ConnectionFactory::class, - Database::class => ConnectionFactory::class, + FeedbackForm::class => ConnectionFactory::class, ]; /** diff --git a/module/Finna/src/Finna/ReservationList/ReservationListService.php b/module/Finna/src/Finna/ReservationList/ReservationListService.php index a3f5808fd46..6e8de9c83af 100644 --- a/module/Finna/src/Finna/ReservationList/ReservationListService.php +++ b/module/Finna/src/Finna/ReservationList/ReservationListService.php @@ -297,25 +297,25 @@ public function saveRecordToReservationList( /** * Set list ordered * - * @param UserEntityInterface $user User to check for rights to list - * @param FinnaResourceListEntityInterface $list List entity or id of the list - * @param Parameters $request Parameters to get values from + * @param UserEntityInterface $user User to check for rights to list + * @param FinnaResourceListEntityInterface $list List entity or id of the list + * @param array $newValues New values to update as key value pairs * * @return void */ public function setListOrdered( UserEntityInterface $user, FinnaResourceListEntityInterface $list, - Parameters $request + array $newValues ): void { if (!$this->userCanEditList($user, $list)) { throw new ListPermissionException('list_access_denied'); } - $list->setPickupDate(DateTime::createFromFormat('Y-m-d', $request->get('pickup_date')))->setOrdered(); - if ($externalId = $request->get('external_id')) { + $list->setPickupDate(DateTime::createFromFormat('Y-m-d', $newValues['pickup_date']))->setOrdered(); + if ($externalId = $newValues['external_id'] ?? null) { $list->setExternalId($externalId); } - if ($connection = $request->get('connection')) { + if ($connection = $newValues['connection'] ?? null) { $list->setConnection($connection); } $this->resourceListService->persistEntity($list); diff --git a/module/Finna/src/Finna/ReservationList/ReservationListStatus.php b/module/Finna/src/Finna/ReservationList/ReservationListStatus.php index 9ea9e588caf..189b5264c4e 100644 --- a/module/Finna/src/Finna/ReservationList/ReservationListStatus.php +++ b/module/Finna/src/Finna/ReservationList/ReservationListStatus.php @@ -42,14 +42,15 @@ enum ReservationListStatus: string { case UNKNOWN = 'unknown'; case IN_PROCESS = 'in_process'; - case HANDLED = 'handled'; + case PROCESSED = 'processed'; case DELIVERED = 'delivered'; case CANCELLED = 'cancelled'; case REPLIED = 'replied'; case REMOVED_ITEM = 'removed_item'; - case LOANED = 'loaned'; + case ON_LOAN = 'on_loan'; case RETURNED = 'returned'; case RENEWED = 'renewed'; + case PENDING = 'pending'; /** * Return a translation key representing the status. @@ -60,4 +61,22 @@ public function getTranslationKey(): string { return 'ReservationList::status_' . $this->value; } + + /** + * Return instance of ENUM by mapping a status key into a proper enum status + * + * @param string $text Value to map + * + * @return string Found mapped value or unknown if not found + */ + public static function mapEnumFromString(string $text): static + { + $statusKeyMappings = [ + 'handled' => 'processed', + 'loaned' => 'on_loan', + ]; + $text = mb_strtolower($text); + $text = $statusKeyMappings[$text] ?? $text; + return ReservationListStatus::tryFrom($text) ?? ReservationListStatus::UNKNOWN; + } } diff --git a/themes/finna2/js/finna-reservation-list.js b/themes/finna2/js/finna-reservation-list.js index 51fcd2c8dff..966b8be112e 100644 --- a/themes/finna2/js/finna-reservation-list.js +++ b/themes/finna2/js/finna-reservation-list.js @@ -14,8 +14,10 @@ finna.reservationList = (function finnaReservationList() { return response.json(); }) .then(responseJSON => { - element.innerText = responseJSON.data; - element.classList.remove('pending'); + if (responseJSON.data && responseJSON.data.status) { + element.innerText = responseJSON.data.status; + element.classList.remove('pending'); + } }); } From 64f5ee2ff3db75b70205b25fcb8ab2ec33461a40 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:00:07 +0200 Subject: [PATCH 04/15] Adjusted sample file to match --- local/config/finna/ReservationList.yaml.sample | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/local/config/finna/ReservationList.yaml.sample b/local/config/finna/ReservationList.yaml.sample index b6a2028eb0c..20d69fe0509 100644 --- a/local/config/finna/ReservationList.yaml.sample +++ b/local/config/finna/ReservationList.yaml.sample @@ -10,9 +10,9 @@ # about where the order is being delivered # LibraryCardSources is used to check for active connection to ILS to be able to use lists # Connection holds information about type of lists: -# FeedbackForm: Default connection, orders handled with sending forms +# feedbackform: Default connection, orders handled with sending forms # handler: email [Optional] Default handler email, other values found in FeedbackForms.yaml primary handlers -# Disec: +# disec: # base_url: Api base url # secret: Api specific secret # use_cat_id: [Optional] Use catalog id for user instead of firstName, lastName, email. Default false. @@ -51,4 +51,4 @@ Institutions: LibraryCardSources: - connection_established_to_use_lists Connection: - type: FeedbackForm + type: feedbackform From f18570f6df283abc415bace1f68ee6e44dbb8d2b Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:04:23 +0200 Subject: [PATCH 05/15] Added missing empty translation --- local/languages/finna/ReservationList/se.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/local/languages/finna/ReservationList/se.ini b/local/languages/finna/ReservationList/se.ini index f6b88851078..da35238a9f1 100644 --- a/local/languages/finna/ReservationList/se.ini +++ b/local/languages/finna/ReservationList/se.ini @@ -40,3 +40,4 @@ status_removed_item = "" status_loaned = "" status_returned = "" status_renewed = "" +status_pending = "" From 389e207d3ac710dfec4a2ece1c14af0c60912490 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:07:47 +0200 Subject: [PATCH 06/15] Moved properties to proper class --- .../src/Finna/ReservationList/AbstractBase.php | 14 -------------- .../src/Finna/ReservationList/FeedbackForm.php | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/module/Finna/src/Finna/ReservationList/AbstractBase.php b/module/Finna/src/Finna/ReservationList/AbstractBase.php index 1b9aeed6ea4..3368a70d984 100644 --- a/module/Finna/src/Finna/ReservationList/AbstractBase.php +++ b/module/Finna/src/Finna/ReservationList/AbstractBase.php @@ -50,20 +50,6 @@ class AbstractBase implements ConnectionInterface, \Laminas\Log\LoggerAwareInter use \VuFind\Log\LoggerAwareTrait; use GetServiceTrait; - /** - * Recipients for email handler defined in ReservationList.yaml - * - * @var array - */ - protected array $recipients; - - /** - * Configured handler to handle form post, defaults to email handler - * - * @var string - */ - protected string $configuredHandler = 'email'; - /** * Constructor * diff --git a/module/Finna/src/Finna/ReservationList/FeedbackForm.php b/module/Finna/src/Finna/ReservationList/FeedbackForm.php index d88edfd4b9a..661f52ee352 100644 --- a/module/Finna/src/Finna/ReservationList/FeedbackForm.php +++ b/module/Finna/src/Finna/ReservationList/FeedbackForm.php @@ -45,6 +45,20 @@ */ class FeedbackForm extends AbstractBase { + /** + * Recipients for email handler defined in ReservationList.yaml + * + * @var array + */ + protected array $recipients; + + /** + * Configured handler to handle form post, defaults to email handler + * + * @var string + */ + protected string $configuredHandler = 'email'; + /** * Places an order * From 83221b922da8fd08e56c24e77f025e900aca730a Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:09:56 +0200 Subject: [PATCH 07/15] Adjusted keys --- local/languages/finna/ReservationList/se.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local/languages/finna/ReservationList/se.ini b/local/languages/finna/ReservationList/se.ini index da35238a9f1..b33d742c57b 100644 --- a/local/languages/finna/ReservationList/se.ini +++ b/local/languages/finna/ReservationList/se.ini @@ -32,12 +32,12 @@ Select = "" ; List statuses: status_unknown = "" status_in_process = "" -status_handled = "" +status_processed = "" status_delivered = "" status_cancelled = "" status_replied = "" status_removed_item = "" -status_loaned = "" +status_on_loan = "" status_returned = "" status_renewed = "" status_pending = "" From 04db089f1fd4182b9a429aa9c0b2fd59e00c84e2 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:57:39 +0200 Subject: [PATCH 08/15] Fixed typos in translations, moved Connection specific classes to their own namespace --- .../config/finna/ReservationList.yaml.sample | 8 +++--- .../languages/finna/ReservationList/en-gb.ini | 6 ++--- local/languages/finna/ReservationList/fi.ini | 2 +- local/languages/finna/ReservationList/sv.ini | 4 +-- module/Finna/config/module.config.php | 4 +-- .../src/Finna/AjaxHandler/ReservationList.php | 2 +- .../AjaxHandler/ReservationListFactory.php | 2 +- .../Controller/ReservationListController.php | 4 +-- .../{ => Connection}/AbstractBase.php | 23 ++++------------ .../{ => Connection}/ConnectionFactory.php | 2 +- .../{ => Connection}/ConnectionInterface.php | 4 +-- .../{ => Connection}/Disec.php | 6 ++--- .../{ => Connection}/FeedbackForm.php | 26 ++++++++++++++----- .../{ => Connection}/PluginManager.php | 2 +- .../ReservationListStatus.php | 2 +- 15 files changed, 49 insertions(+), 48 deletions(-) rename module/Finna/src/Finna/ReservationList/{ => Connection}/AbstractBase.php (80%) rename module/Finna/src/Finna/ReservationList/{ => Connection}/ConnectionFactory.php (98%) rename module/Finna/src/Finna/ReservationList/{ => Connection}/ConnectionInterface.php (96%) rename module/Finna/src/Finna/ReservationList/{ => Connection}/Disec.php (98%) rename module/Finna/src/Finna/ReservationList/{ => Connection}/FeedbackForm.php (79%) rename module/Finna/src/Finna/ReservationList/{ => Connection}/PluginManager.php (98%) rename module/Finna/src/Finna/ReservationList/{ => Connection}/ReservationListStatus.php (98%) diff --git a/local/config/finna/ReservationList.yaml.sample b/local/config/finna/ReservationList.yaml.sample index 20d69fe0509..ecb3f53fc1b 100644 --- a/local/config/finna/ReservationList.yaml.sample +++ b/local/config/finna/ReservationList.yaml.sample @@ -9,10 +9,10 @@ # List can contain same information as under institution information to be more specific # about where the order is being delivered # LibraryCardSources is used to check for active connection to ILS to be able to use lists -# Connection holds information about type of lists: -# feedbackform: Default connection, orders handled with sending forms -# handler: email [Optional] Default handler email, other values found in FeedbackForms.yaml primary handlers -# disec: +# Connection defines how the orders are handled with institutions: +# Type: +# feedbackform: Uses feedback forms for sending orders, see FeedbackForms.yaml.sample : ReservationListRequest +# disec: Uses Disec api for sending orders # base_url: Api base url # secret: Api specific secret # use_cat_id: [Optional] Use catalog id for user instead of firstName, lastName, email. Default false. diff --git a/local/languages/finna/ReservationList/en-gb.ini b/local/languages/finna/ReservationList/en-gb.ini index 3b533375ed8..5fb313bcdd9 100644 --- a/local/languages/finna/ReservationList/en-gb.ini +++ b/local/languages/finna/ReservationList/en-gb.ini @@ -32,12 +32,12 @@ Select = "Select" ; List statuses: status_unknown = "" status_in_process = "In process" -status_processed = "Handled" +status_processed = "Processed" status_delivered = "Delivered" -status_cancelled = "Canceled" +status_canceled = "Cancelled" status_replied = "Replied" status_removed_item = "Item removed" -status_on_loan = "Loaned" +status_on_loan = "On Loan" status_returned = "Returned" status_renewed = "Renewed" status_pending = "Pending" diff --git a/local/languages/finna/ReservationList/fi.ini b/local/languages/finna/ReservationList/fi.ini index 9628c5def87..485e1c3280f 100644 --- a/local/languages/finna/ReservationList/fi.ini +++ b/local/languages/finna/ReservationList/fi.ini @@ -34,7 +34,7 @@ status_unknown = "" status_in_process = "Käsittelyssä" status_processed = "Käsitelty" status_delivered = "Toimitettu" -status_cancelled = "Peruutettu" +status_canceled = "Peruutettu" status_replied = "Vastattu" status_removed_item = "Aineisto poistettu" status_on_loan = "Lainassa" diff --git a/local/languages/finna/ReservationList/sv.ini b/local/languages/finna/ReservationList/sv.ini index 39bc1c23f26..ef9d88f9bd5 100644 --- a/local/languages/finna/ReservationList/sv.ini +++ b/local/languages/finna/ReservationList/sv.ini @@ -34,10 +34,10 @@ status_unknown = "" status_in_process = "Behandlas" status_processed = "Behandlad" status_delivered = "Levererad" -status_cancelled = "Annulerad" +status_canceled = "Annullerad" status_replied = "Besvarad" status_removed_item = "Objekt borttaget" -status_on_loan = "Lånad" +status_on_loan = "Utlånad" status_returned = "Returnerad" status_renewed = "Förnyad" status_pending = "Väntar" diff --git a/module/Finna/config/module.config.php b/module/Finna/config/module.config.php index 800eef2c836..1c69311062a 100644 --- a/module/Finna/config/module.config.php +++ b/module/Finna/config/module.config.php @@ -381,7 +381,7 @@ 'Finna\Statistics\Driver\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'Finna\Statistics\EventHandler' => 'Finna\Statistics\EventHandlerFactory', \Finna\ReservationList\ReservationListService::class => \Finna\ReservationList\ReservationListServiceFactory::class, - \Finna\ReservationList\PluginManager::class => \VuFind\ServiceManager\AbstractPluginManagerFactory::class, + \Finna\ReservationList\Connection\PluginManager::class => \VuFind\ServiceManager\AbstractPluginManagerFactory::class, 'Finna\Favorites\FavoritesService' => 'Finna\Favorites\FavoritesServiceFactory', 'Finna\View\CustomElement\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'Finna\Video\Handler\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', @@ -767,7 +767,7 @@ ], 'onlinepayment_handler' => [ /* see Finna\OnlinePayment\Handler\PluginManager for defaults */ ], 'video_handler' => [ /* see Finna\Video\Handler\PluginManager for defaults */ ], - 'reservationlist' => [ /* see Finna\ReservationList\PluginManager for defaults */ ], + 'reservationlist_connection' => [ /* see Finna\ReservationList\Connection\PluginManager for defaults */ ], 'recommend' => [ 'factories' => [ 'VuFind\Recommend\CollectionSideFacets' => 'Finna\Recommend\Factory::getCollectionSideFacets', diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationList.php b/module/Finna/src/Finna/AjaxHandler/ReservationList.php index 43c08a4f0cd..e9ea3cbf1eb 100644 --- a/module/Finna/src/Finna/AjaxHandler/ReservationList.php +++ b/module/Finna/src/Finna/AjaxHandler/ReservationList.php @@ -29,7 +29,7 @@ namespace Finna\AjaxHandler; -use Finna\ReservationList\PluginManager; +use Finna\ReservationList\Connection\PluginManager; use Finna\ReservationList\ReservationListService; use Laminas\Mvc\Controller\Plugin\Params; use VuFind\Db\Entity\UserEntityInterface; diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php b/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php index fb58a3171c4..8f7187ef1b1 100644 --- a/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php +++ b/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php @@ -69,7 +69,7 @@ public function __invoke( return new $requestedName( $container->get(\VuFind\Auth\Manager::class)->getUserObject(), $container->get(\Finna\ReservationList\ReservationListService::class), - $container->get(\Finna\ReservationList\PluginManager::class), + $container->get(\Finna\ReservationList\Connection\PluginManager::class), ); } } diff --git a/module/Finna/src/Finna/Controller/ReservationListController.php b/module/Finna/src/Finna/Controller/ReservationListController.php index 9d8544388b0..0e708c5d41e 100644 --- a/module/Finna/src/Finna/Controller/ReservationListController.php +++ b/module/Finna/src/Finna/Controller/ReservationListController.php @@ -346,7 +346,7 @@ public function placeOrderAction() return $view; } $connectionType = $listProperties['Connection']['type']; - $handler = $this->getService(\Finna\ReservationList\PluginManager::class)->get($connectionType); + $handler = $this->getService(\Finna\ReservationList\Connection\PluginManager::class)->get($connectionType); $handler->init($listProperties); $gatheredPostValues = [ 'firstName' => $postRequest->get('firstName'), @@ -358,7 +358,7 @@ public function placeOrderAction() 'pickup_date' => $postRequest->get('pickup_date'), 'resourceIDs' => $postRequest->get('resourceIDs'), ]; - if ($handler instanceof \Finna\ReservationList\FeedbackForm) { + if ($handler instanceof \Finna\ReservationList\Connection\FeedbackForm) { $result = $handler->placeOrder($this->params(), $user, $form); } else { $result = $handler->placeOrder($gatheredPostValues, $user, $form); diff --git a/module/Finna/src/Finna/ReservationList/AbstractBase.php b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php similarity index 80% rename from module/Finna/src/Finna/ReservationList/AbstractBase.php rename to module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php index 3368a70d984..7f3d2a8911d 100644 --- a/module/Finna/src/Finna/ReservationList/AbstractBase.php +++ b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php @@ -27,7 +27,7 @@ * @link https://vufind.org/wiki/development:plugins:controllers Wiki */ -namespace Finna\ReservationList; +namespace Finna\ReservationList\Connection; use Finna\Db\Entity\FinnaResourceListEntityInterface; use Laminas\Mvc\Controller\Plugin\Params; @@ -45,7 +45,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org Main Site */ -class AbstractBase implements ConnectionInterface, \Laminas\Log\LoggerAwareInterface +abstract class AbstractBase implements ConnectionInterface, \Laminas\Log\LoggerAwareInterface { use \VuFind\Log\LoggerAwareTrait; use GetServiceTrait; @@ -69,13 +69,7 @@ public function __construct(ContainerInterface $serviceLocator) * * @return array [external_id: Id in external service or null, success: true or false] */ - public function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array - { - return [ - 'success' => false, - 'external_id' => null, - ]; - } + public abstract function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array; /** * Check list status. Used for external services. @@ -85,11 +79,7 @@ public function placeOrder(array|Params $postValues, UserEntityInterface $user, * * @return string */ - public function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string - { - $status = ReservationListStatus::UNKNOWN; - return $status->getTranslationKey(); - } + public abstract function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string; /** * Initialize connection handler @@ -98,8 +88,5 @@ public function getListStatus(FinnaResourceListEntityInterface $list, UserEntity * * @return static */ - public function init(array $config): self - { - return $this; - } + public abstract function init(array $config): static; } diff --git a/module/Finna/src/Finna/ReservationList/ConnectionFactory.php b/module/Finna/src/Finna/ReservationList/Connection/ConnectionFactory.php similarity index 98% rename from module/Finna/src/Finna/ReservationList/ConnectionFactory.php rename to module/Finna/src/Finna/ReservationList/Connection/ConnectionFactory.php index a31aae5146b..d16086cc3b4 100644 --- a/module/Finna/src/Finna/ReservationList/ConnectionFactory.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ConnectionFactory.php @@ -27,7 +27,7 @@ * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki */ -namespace Finna\ReservationList; +namespace Finna\ReservationList\Connection; use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerInterface; diff --git a/module/Finna/src/Finna/ReservationList/ConnectionInterface.php b/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php similarity index 96% rename from module/Finna/src/Finna/ReservationList/ConnectionInterface.php rename to module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php index 6fbfefc87db..e07de3fae88 100644 --- a/module/Finna/src/Finna/ReservationList/ConnectionInterface.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php @@ -27,7 +27,7 @@ * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki */ -namespace Finna\ReservationList; +namespace Finna\ReservationList\Connection; use Finna\Db\Entity\FinnaResourceListEntityInterface; use Laminas\Mvc\Controller\Plugin\Params; @@ -74,5 +74,5 @@ public function getListStatus(FinnaResourceListEntityInterface $list, UserEntity * @return static * @throws \Exception If connection is not configured properly */ - public function init(array $config): self; + public function init(array $config): static; } diff --git a/module/Finna/src/Finna/ReservationList/Disec.php b/module/Finna/src/Finna/ReservationList/Connection/Disec.php similarity index 98% rename from module/Finna/src/Finna/ReservationList/Disec.php rename to module/Finna/src/Finna/ReservationList/Connection/Disec.php index 73d894c146a..886a841fa4c 100644 --- a/module/Finna/src/Finna/ReservationList/Disec.php +++ b/module/Finna/src/Finna/ReservationList/Connection/Disec.php @@ -3,7 +3,7 @@ /** * Disec connection handler * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * @@ -27,7 +27,7 @@ * @link https://vufind.org/wiki/development:plugins:controllers Wiki */ -namespace Finna\ReservationList; +namespace Finna\ReservationList\Connection; use Finna\Db\Entity\FinnaResourceListEntityInterface; use Laminas\Mvc\Controller\Plugin\Params; @@ -173,7 +173,7 @@ public function getListStatus(FinnaResourceListEntityInterface $list, UserEntity * @return static * @throws \Exception If Disec connection is not configured properly */ - public function init(array $config): self + public function init(array $config): static { try { $baseUrl = $config['Connection']['base_url']; diff --git a/module/Finna/src/Finna/ReservationList/FeedbackForm.php b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php similarity index 79% rename from module/Finna/src/Finna/ReservationList/FeedbackForm.php rename to module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php index 661f52ee352..47c20ff1863 100644 --- a/module/Finna/src/Finna/ReservationList/FeedbackForm.php +++ b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php @@ -3,7 +3,7 @@ /** * FeedbackForm connection handler * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * @@ -27,9 +27,10 @@ * @link https://vufind.org/wiki/development:plugins:controllers Wiki */ -namespace Finna\ReservationList; +namespace Finna\ReservationList\Connection; use Exception; +use Finna\Db\Entity\FinnaResourceListEntityInterface; use Laminas\Mvc\Controller\Plugin\Params; use VuFind\Db\Entity\UserEntityInterface; use VuFind\Form\Form; @@ -82,21 +83,34 @@ public function placeOrder(array|Params $postValues, UserEntityInterface $user, ]; } + /** + * Check list status. Used for external services. + * + * @param FinnaResourceListEntityInterface $list List to check for status + * @param UserEntityInterface $user Current logged in user + * + * @return string + */ + public function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string + { + $status = ReservationListStatus::UNKNOWN; + return $status->getTranslationKey(); + } + /** * Initialize connection handler * * @param array $config List specific configuration from ReservationList.yaml * * @return static - * @throws \Exception If Database connection is not configured properly + * @throws \Exception If FeedbackForm connection is not configured properly */ - public function init(array $config): self + public function init(array $config): static { try { $this->recipients = $config['Recipient']; - $this->configuredHandler = $config['Connection']['handler'] ?? 'email'; } catch (\Exception $e) { - throw new \Exception('Database: Invalid configuration'); + throw new \Exception('FeedbackForm: Invalid configuration'); } return $this; } diff --git a/module/Finna/src/Finna/ReservationList/PluginManager.php b/module/Finna/src/Finna/ReservationList/Connection/PluginManager.php similarity index 98% rename from module/Finna/src/Finna/ReservationList/PluginManager.php rename to module/Finna/src/Finna/ReservationList/Connection/PluginManager.php index af260671703..707ad6470c7 100644 --- a/module/Finna/src/Finna/ReservationList/PluginManager.php +++ b/module/Finna/src/Finna/ReservationList/Connection/PluginManager.php @@ -27,7 +27,7 @@ * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki */ -namespace Finna\ReservationList; +namespace Finna\ReservationList\Connection; /** * Reservation list plugin manager diff --git a/module/Finna/src/Finna/ReservationList/ReservationListStatus.php b/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php similarity index 98% rename from module/Finna/src/Finna/ReservationList/ReservationListStatus.php rename to module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php index 189b5264c4e..3324044a8c1 100644 --- a/module/Finna/src/Finna/ReservationList/ReservationListStatus.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php @@ -27,7 +27,7 @@ * @link http://vufind.org/wiki/vufind2:developer_manual Wiki */ -namespace Finna\ReservationList; +namespace Finna\ReservationList\Connection; /** * Reservation list status enum. From 8427a2de452552de5694a11f57b9e36933797f18 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:40:24 +0200 Subject: [PATCH 09/15] Manipulate post params less, use form more properly. --- .../config/finna/ReservationList.yaml.sample | 2 +- .../languages/finna/ReservationList/en-gb.ini | 4 --- local/languages/finna/ReservationList/fi.ini | 4 --- local/languages/finna/ReservationList/se.ini | 6 +--- local/languages/finna/ReservationList/sv.ini | 4 --- .../Controller/ReservationListController.php | 24 +++---------- module/Finna/src/Finna/Form/Form.php | 22 +++++++++++- .../Connection/AbstractBase.php | 14 ++++---- .../Connection/ConnectionFactory.php | 2 +- .../Connection/ConnectionInterface.php | 10 +++--- .../ReservationList/Connection/Disec.php | 34 +++++++++---------- .../Connection/FeedbackForm.php | 26 +++++--------- .../Connection/PluginManager.php | 2 +- .../Connection/ReservationListStatus.php | 7 +--- .../ReservationListService.php | 3 +- 15 files changed, 67 insertions(+), 97 deletions(-) diff --git a/local/config/finna/ReservationList.yaml.sample b/local/config/finna/ReservationList.yaml.sample index ecb3f53fc1b..50bd4e7d077 100644 --- a/local/config/finna/ReservationList.yaml.sample +++ b/local/config/finna/ReservationList.yaml.sample @@ -11,7 +11,7 @@ # LibraryCardSources is used to check for active connection to ILS to be able to use lists # Connection defines how the orders are handled with institutions: # Type: -# feedbackform: Uses feedback forms for sending orders, see FeedbackForms.yaml.sample : ReservationListRequest +# feedbackform: Uses feedback forms for sending orders, see FeedbackForms.yaml.sample : ReservationListRequest for examples # disec: Uses Disec api for sending orders # base_url: Api base url # secret: Api specific secret diff --git a/local/languages/finna/ReservationList/en-gb.ini b/local/languages/finna/ReservationList/en-gb.ini index 5fb313bcdd9..abef4c38fdf 100644 --- a/local/languages/finna/ReservationList/en-gb.ini +++ b/local/languages/finna/ReservationList/en-gb.ini @@ -31,12 +31,8 @@ Select = "Select" ; List statuses: status_unknown = "" -status_in_process = "In process" -status_processed = "Processed" status_delivered = "Delivered" status_canceled = "Cancelled" -status_replied = "Replied" -status_removed_item = "Item removed" status_on_loan = "On Loan" status_returned = "Returned" status_renewed = "Renewed" diff --git a/local/languages/finna/ReservationList/fi.ini b/local/languages/finna/ReservationList/fi.ini index 485e1c3280f..37ed7eb459e 100644 --- a/local/languages/finna/ReservationList/fi.ini +++ b/local/languages/finna/ReservationList/fi.ini @@ -31,12 +31,8 @@ Select = "Valitse" ; List statuses: status_unknown = "" -status_in_process = "Käsittelyssä" -status_processed = "Käsitelty" status_delivered = "Toimitettu" status_canceled = "Peruutettu" -status_replied = "Vastattu" -status_removed_item = "Aineisto poistettu" status_on_loan = "Lainassa" status_returned = "Palautettu" status_renewed = "Uusittu" diff --git a/local/languages/finna/ReservationList/se.ini b/local/languages/finna/ReservationList/se.ini index b33d742c57b..620e8f145a5 100644 --- a/local/languages/finna/ReservationList/se.ini +++ b/local/languages/finna/ReservationList/se.ini @@ -31,12 +31,8 @@ Select = "" ; List statuses: status_unknown = "" -status_in_process = "" -status_processed = "" status_delivered = "" -status_cancelled = "" -status_replied = "" -status_removed_item = "" +status_canceled = "" status_on_loan = "" status_returned = "" status_renewed = "" diff --git a/local/languages/finna/ReservationList/sv.ini b/local/languages/finna/ReservationList/sv.ini index ef9d88f9bd5..cf88627e577 100644 --- a/local/languages/finna/ReservationList/sv.ini +++ b/local/languages/finna/ReservationList/sv.ini @@ -31,12 +31,8 @@ Select = "Välj" ; List statuses: status_unknown = "" -status_in_process = "Behandlas" -status_processed = "Behandlad" status_delivered = "Levererad" status_canceled = "Annullerad" -status_replied = "Besvarad" -status_removed_item = "Objekt borttaget" status_on_loan = "Utlånad" status_returned = "Returnerad" status_renewed = "Förnyad" diff --git a/module/Finna/src/Finna/Controller/ReservationListController.php b/module/Finna/src/Finna/Controller/ReservationListController.php index 0e708c5d41e..4063a2eae40 100644 --- a/module/Finna/src/Finna/Controller/ReservationListController.php +++ b/module/Finna/src/Finna/Controller/ReservationListController.php @@ -311,7 +311,7 @@ public function placeOrderAction() $resourceIds[] = $resource->getSource() . '|' . $resource->getRecordId(); } $postRequest = $request->getPost(); - // Set reservationlist specific form values + // Set reservation list specific form values $postRequest ->set('rl_list_id', $listId) ->set('rl_institution', $list->getInstitution()) @@ -321,7 +321,6 @@ public function placeOrderAction() $form = $this->getService(\Finna\Form\Form::class); $form->setFormId(formId: $formId, prefill: $postRequest->toArray()); - if (!$form->isEnabled()) { throw new \VuFind\Exception\Forbidden("Form '$formId' is disabled"); } @@ -348,25 +347,10 @@ public function placeOrderAction() $connectionType = $listProperties['Connection']['type']; $handler = $this->getService(\Finna\ReservationList\Connection\PluginManager::class)->get($connectionType); $handler->init($listProperties); - $gatheredPostValues = [ - 'firstName' => $postRequest->get('firstName'), - 'lastName' => $postRequest->get('lastName'), - 'email' => $postRequest->get('email'), - 'record_ids' => $postRequest->get('record_ids'), - 'phone' => $postRequest->get('phone'), - 'message' => $postRequest->get('message'), - 'pickup_date' => $postRequest->get('pickup_date'), - 'resourceIDs' => $postRequest->get('resourceIDs'), - ]; - if ($handler instanceof \Finna\ReservationList\Connection\FeedbackForm) { - $result = $handler->placeOrder($this->params(), $user, $form); - } else { - $result = $handler->placeOrder($gatheredPostValues, $user, $form); - } + $result = $handler->placeOrder($this->params(), $user, $form); if ($result['success']) { - $gatheredPostValues['external_id'] = $result['external_id']; - $gatheredPostValues['connection'] = $connectionType; - $this->reservationListService->setListOrdered($user, $list, $gatheredPostValues); + $result['connection'] = $connectionType; + $this->reservationListService->setListOrdered($user, $list, $result); $this->flashMessenger()->addSuccessMessage($form->getSubmitResponse()); return $this->getRefreshResponse(); } else { diff --git a/module/Finna/src/Finna/Form/Form.php b/module/Finna/src/Finna/Form/Form.php index 6a31acf8a08..50997a68ece 100644 --- a/module/Finna/src/Finna/Form/Form.php +++ b/module/Finna/src/Finna/Form/Form.php @@ -161,6 +161,13 @@ class Form extends \VuFind\Form\Form */ protected $recordLoader = null; + /** + * Recipients for reservation lists + * + * @var array + */ + protected array $reservationListRecipients = []; + /** * Set form id * @@ -334,6 +341,19 @@ public function reportPatronId(): bool return (bool)($this->formConfig['includePatronId'] ?? false); } + /** + * Set recipients used in reservation lists as lists can have same configuration base + * but contain different recipients for each list + * + * @param array $recipients Array containing recipients [name, email] + * + * @return void + */ + public function setReservationListRecipients(array $recipients): void + { + $this->reservationListRecipients = $recipients; + } + /** * Return form recipient. * @@ -345,7 +365,7 @@ public function getRecipient($postParams = null) { // Always get recipients from postparams if ($this->getFormId() === self::RESERVATION_LIST_REQUEST) { - return $postParams['recipient']; + return $this->reservationListRecipients; } // Get recipient email address for feedback form from data source // configuration: diff --git a/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php index 7f3d2a8911d..5ba2506863b 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php +++ b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php @@ -3,7 +3,7 @@ /** * Connection abstract base * - * PHP version 8.1 + * PHP Version 8 * * Copyright (C) The National Library of Finland 2024. * @@ -63,13 +63,13 @@ public function __construct(ContainerInterface $serviceLocator) /** * Places an order * - * @param array|Params $postValues Key value pairs of post parameters to send or params plugin - * @param UserEntityInterface $user User entity - * @param Form $form Form posted when submitting the order + * @param Params $params Params plugin + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order * * @return array [external_id: Id in external service or null, success: true or false] */ - public abstract function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array; + abstract public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array; /** * Check list status. Used for external services. @@ -79,7 +79,7 @@ public abstract function placeOrder(array|Params $postValues, UserEntityInterfac * * @return string */ - public abstract function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string; + abstract public function getListStatus(FinnaResourceListEntityInterface $list, UserEntityInterface $user): string; /** * Initialize connection handler @@ -88,5 +88,5 @@ public abstract function getListStatus(FinnaResourceListEntityInterface $list, U * * @return static */ - public abstract function init(array $config): static; + abstract public function init(array $config): static; } diff --git a/module/Finna/src/Finna/ReservationList/Connection/ConnectionFactory.php b/module/Finna/src/Finna/ReservationList/Connection/ConnectionFactory.php index d16086cc3b4..8f063b29961 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/ConnectionFactory.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ConnectionFactory.php @@ -3,7 +3,7 @@ /** * Connection factory * - * PHP version 8.1 + * PHP Version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php b/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php index e07de3fae88..5ee67bb1d82 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php @@ -3,7 +3,7 @@ /** * Reservation list connection plugin interface * - * PHP version 8.1 + * PHP Version 8 * * Copyright (C) The National Library of Finland 2024. * @@ -48,13 +48,13 @@ interface ConnectionInterface /** * Places an order * - * @param array|Params $postValues Key value pairs of post parameters to send or params plugin - * @param UserEntityInterface $user User entity - * @param Form $form Form posted when submitting the order + * @param Params $params Params plugin + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order * * @return array [external_id: Id in external service or null, success: true or false] */ - public function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array; + public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array; /** * Check list status. Used for external services. diff --git a/module/Finna/src/Finna/ReservationList/Connection/Disec.php b/module/Finna/src/Finna/ReservationList/Connection/Disec.php index 886a841fa4c..798b1a7470b 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/Disec.php +++ b/module/Finna/src/Finna/ReservationList/Connection/Disec.php @@ -34,8 +34,6 @@ use VuFind\Db\Entity\UserEntityInterface; use VuFind\Form\Form; -use function is_array; - /** * Disec connection handler * @@ -81,17 +79,14 @@ class Disec extends AbstractBase /** * Places an order * - * @param array|Params $postValues Key value pairs of post parameters to send or params plugin - * @param UserEntityInterface $user User entity - * @param Form $form Form posted when submitting the order + * @param Params $params Params plugin + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order * * @return array [external_id: Id in external service or null, success: true or false] */ - public function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array + public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array { - if (!is_array($postValues)) { - throw new \Exception('ReservationList Disec: Illegal parameter type.'); - } $data = []; $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($this->ordersUrl); $client->setHeaders($this->requestHeaders); @@ -99,29 +94,30 @@ public function placeOrder(array|Params $postValues, UserEntityInterface $user, $resources = []; $recordLoader = $this->getService(\VuFind\Record\Loader::class); - foreach ($recordLoader->loadBatch($postValues['resourceIDs']) as $record) { + foreach ($recordLoader->loadBatch($params->fromPost('resourceIDs', [])) as $record) { if ($identifiers = $record->tryMethod('getIdentifier', [])) { $resources[] = array_shift($identifiers); } } $data = [ 'resourceIds' => $resources, - 'customer' => [ - 'firstName' => $postValues['firstName'], - 'lastName' => $postValues['lastName'], - 'email' => $postValues['email'], - ], - 'contentInfo' => $postValues['message'] . PHP_EOL, + 'contentInfo' => $params->fromPost('message', '') . PHP_EOL, ]; - $data['contentInfo'] .= $postValues['pickup_date'] . PHP_EOL; + $data['contentInfo'] .= $params->fromPost('pickup_date') . PHP_EOL; if ($catId = $user->getCatId()) { [, $id] = explode('.', $catId); if ($this->useCatId) { $data['kohaId'] = (int)$id; - unset($data['customer']); } $data['contentInfo'] .= 'cat_id: ' . $id; } + if (empty($data['kohaId'])) { + $data['customer'] = [ + 'firstName' => $params->fromPost('firstName') ?? $user->getFirstname(), + 'lastName' => $params->fromPost('lastName') ?? $user->getLastname(), + 'email' => $params->fromPost('email') ?? $user->getEmail(), + ]; + } $client->setRawBody(json_encode($data)); $response = $client->send(); @@ -130,12 +126,14 @@ public function placeOrder(array|Params $postValues, UserEntityInterface $user, return [ 'success' => true, 'external_id' => $body['id'], + 'pickup_date' => $params->fromPost('pickup_date', ''), ]; } $this->debug('Disec: failed to place order: ' . $response->getBody()); return [ 'success' => false, 'external_id' => null, + 'pickup_date' => null, ]; } diff --git a/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php index 47c20ff1863..a584d38d197 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php +++ b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php @@ -29,7 +29,6 @@ namespace Finna\ReservationList\Connection; -use Exception; use Finna\Db\Entity\FinnaResourceListEntityInterface; use Laminas\Mvc\Controller\Plugin\Params; use VuFind\Db\Entity\UserEntityInterface; @@ -53,33 +52,24 @@ class FeedbackForm extends AbstractBase */ protected array $recipients; - /** - * Configured handler to handle form post, defaults to email handler - * - * @var string - */ - protected string $configuredHandler = 'email'; - /** * Places an order * - * @param array|Params $postValues Key value pairs of post parameters to send or params plugin - * @param UserEntityInterface $user User entity - * @param Form $form Form posted when submitting the order + * @param Params $params Params plugin + * @param UserEntityInterface $user User entity + * @param Form $form Form posted when submitting the order * * @return array [external_id: Id in external service or null, success: true or false] */ - public function placeOrder(array|Params $postValues, UserEntityInterface $user, Form $form = null): array + public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array { - if (!($postValues instanceof Params)) { - throw new Exception('ReservationList FeedbackForm: Illegal parameter type.'); - } - $postValues->getController()->getRequest()->getPost()->set('recipient', $this->recipients); - $result = $this->getService(\VuFind\Form\Handler\PluginManager::class) - ->get($this->configuredHandler)->handle($form, $postValues, $user); + // Assign external recipients as lists can contain different recipients even if form base is the same + $form->setReservationListRecipients($this->recipients); + $result = $form->getPrimaryHandler()->handle($form, $params, $user); return [ 'success' => $result, 'external_id' => null, + 'pickup_date' => $params->fromPost('pickup_date', ''), ]; } diff --git a/module/Finna/src/Finna/ReservationList/Connection/PluginManager.php b/module/Finna/src/Finna/ReservationList/Connection/PluginManager.php index 707ad6470c7..ff89d176a50 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/PluginManager.php +++ b/module/Finna/src/Finna/ReservationList/Connection/PluginManager.php @@ -3,7 +3,7 @@ /** * Reservation list connection plugin manager * - * PHP version 8.1 + * PHP Version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php b/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php index 3324044a8c1..b0562d3426f 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php @@ -3,7 +3,7 @@ /** * Reservation list status enum. * - * PHP version 8.1 + * PHP Version 8 * * Copyright (C) The National Library of Finland 2024. * @@ -41,12 +41,8 @@ enum ReservationListStatus: string { case UNKNOWN = 'unknown'; - case IN_PROCESS = 'in_process'; - case PROCESSED = 'processed'; case DELIVERED = 'delivered'; case CANCELLED = 'cancelled'; - case REPLIED = 'replied'; - case REMOVED_ITEM = 'removed_item'; case ON_LOAN = 'on_loan'; case RETURNED = 'returned'; case RENEWED = 'renewed'; @@ -72,7 +68,6 @@ public function getTranslationKey(): string public static function mapEnumFromString(string $text): static { $statusKeyMappings = [ - 'handled' => 'processed', 'loaned' => 'on_loan', ]; $text = mb_strtolower($text); diff --git a/module/Finna/src/Finna/ReservationList/ReservationListService.php b/module/Finna/src/Finna/ReservationList/ReservationListService.php index 6e8de9c83af..718b74f6cdb 100644 --- a/module/Finna/src/Finna/ReservationList/ReservationListService.php +++ b/module/Finna/src/Finna/ReservationList/ReservationListService.php @@ -35,7 +35,6 @@ use Finna\Db\Entity\FinnaResourceListEntityInterface; use Finna\Db\Service\FinnaResourceListResourceServiceInterface; use Finna\Db\Service\FinnaResourceListServiceInterface; -use Laminas\Config\Config; use Laminas\Session\Container; use Laminas\Stdlib\Parameters; use VuFind\Db\Entity\ResourceEntityInterface; @@ -91,7 +90,7 @@ class ReservationListService implements TranslatorAwareInterface, DbServiceAware 'LibraryCardSources' => [], 'CheckResourceStatus' => false, 'Connection' => [ - 'type' => 'Database', + 'type' => 'feedbackform', ], 'Identifier' => false, ]; From 371302a4b29faf13b188ad4696c0161fad600f3f Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:59:04 +0200 Subject: [PATCH 10/15] Adjusted setListOrdered default values set --- .../Entity/FinnaResourceListEntityInterface.php | 4 ++-- .../src/Finna/Db/Row/FinnaResourceList.php | 4 ++-- .../ReservationList/ReservationListService.php | 17 ++++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php b/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php index f16f36afd0b..4bce202e821 100644 --- a/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php +++ b/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php @@ -234,9 +234,9 @@ public function getExternalId(): ?string; /** * Set external id * - * @param string $id External id + * @param ?string $id External id * * @return static */ - public function setExternalId(string $id): static; + public function setExternalId(?string $id): static; } diff --git a/module/Finna/src/Finna/Db/Row/FinnaResourceList.php b/module/Finna/src/Finna/Db/Row/FinnaResourceList.php index cd5d3dc7a5c..031ad66f91a 100644 --- a/module/Finna/src/Finna/Db/Row/FinnaResourceList.php +++ b/module/Finna/src/Finna/Db/Row/FinnaResourceList.php @@ -328,11 +328,11 @@ public function getExternalId(): ?string /** * Set the external id * - * @param string $id External id + * @param ?string $id External id * * @return static */ - public function setExternalId(string $id): static + public function setExternalId(?string $id): static { $this->external_id = $id; return $this; diff --git a/module/Finna/src/Finna/ReservationList/ReservationListService.php b/module/Finna/src/Finna/ReservationList/ReservationListService.php index 718b74f6cdb..11ff7ebfef5 100644 --- a/module/Finna/src/Finna/ReservationList/ReservationListService.php +++ b/module/Finna/src/Finna/ReservationList/ReservationListService.php @@ -77,6 +77,13 @@ class ReservationListService implements TranslatorAwareInterface, DbServiceAware */ public const RESOURCE_LIST_TYPE = 'reservationlist'; + /** + * Default connection handler used for list connections + * + * @var string + */ + public const DEFAULT_CONNECTION_HANDLER = 'feedbackform'; + /** * Default values for list config * @@ -90,7 +97,7 @@ class ReservationListService implements TranslatorAwareInterface, DbServiceAware 'LibraryCardSources' => [], 'CheckResourceStatus' => false, 'Connection' => [ - 'type' => 'feedbackform', + 'type' => self::DEFAULT_CONNECTION_HANDLER, ], 'Identifier' => false, ]; @@ -311,12 +318,8 @@ public function setListOrdered( throw new ListPermissionException('list_access_denied'); } $list->setPickupDate(DateTime::createFromFormat('Y-m-d', $newValues['pickup_date']))->setOrdered(); - if ($externalId = $newValues['external_id'] ?? null) { - $list->setExternalId($externalId); - } - if ($connection = $newValues['connection'] ?? null) { - $list->setConnection($connection); - } + $list->setExternalId($newValues['external_id'] ?? null); + $list->setConnection($newValues['connection'] ?? self::DEFAULT_CONNECTION_HANDLER); $this->resourceListService->persistEntity($list); } From a5f3652638825a1369f9f95de827e4f5472e1e70 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:57:49 +0200 Subject: [PATCH 11/15] Moved reservation list specific form functionality to its own class --- module/Finna/config/module.config.php | 1 + .../Finna/Controller/FeedbackController.php | 2 +- .../Controller/ReservationListController.php | 6 +- module/Finna/src/Finna/Form/Form.php | 18 +--- .../Connection/AbstractBase.php | 2 +- .../Connection/ConnectionInterface.php | 2 +- .../ReservationList/Connection/Disec.php | 2 +- .../Connection/FeedbackForm.php | 2 +- .../src/Finna/ReservationList/Form/Form.php | 102 ++++++++++++++++++ 9 files changed, 112 insertions(+), 25 deletions(-) create mode 100644 module/Finna/src/Finna/ReservationList/Form/Form.php diff --git a/module/Finna/config/module.config.php b/module/Finna/config/module.config.php index 1c69311062a..e59435cae06 100644 --- a/module/Finna/config/module.config.php +++ b/module/Finna/config/module.config.php @@ -380,6 +380,7 @@ 'Finna\Service\UserPreferenceService' => 'Finna\Service\UserPreferenceServiceFactory', 'Finna\Statistics\Driver\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', 'Finna\Statistics\EventHandler' => 'Finna\Statistics\EventHandlerFactory', + \Finna\ReservationList\Form\Form::class => \Finna\Form\FormFactory::class, \Finna\ReservationList\ReservationListService::class => \Finna\ReservationList\ReservationListServiceFactory::class, \Finna\ReservationList\Connection\PluginManager::class => \VuFind\ServiceManager\AbstractPluginManagerFactory::class, 'Finna\Favorites\FavoritesService' => 'Finna\Favorites\FavoritesServiceFactory', diff --git a/module/Finna/src/Finna/Controller/FeedbackController.php b/module/Finna/src/Finna/Controller/FeedbackController.php index 5ae8637ad3b..4bd8e39daf3 100644 --- a/module/Finna/src/Finna/Controller/FeedbackController.php +++ b/module/Finna/src/Finna/Controller/FeedbackController.php @@ -58,7 +58,7 @@ public function formAction() { // Always forward reservation list orders to reservation list controller $formId = $this->params()->fromRoute('id', $this->params()->fromQuery('id')); - if ($formId === \Finna\Form\Form::RESERVATION_LIST_REQUEST) { + if ($formId === \Finna\ReservationList\Form\Form::RESERVATION_LIST_REQUEST) { return $this->forwardTo('ReservationList', 'PlaceOrder'); } // Copy any record_id from query params to post params so that it's available diff --git a/module/Finna/src/Finna/Controller/ReservationListController.php b/module/Finna/src/Finna/Controller/ReservationListController.php index 4063a2eae40..bfea48c682e 100644 --- a/module/Finna/src/Finna/Controller/ReservationListController.php +++ b/module/Finna/src/Finna/Controller/ReservationListController.php @@ -35,7 +35,7 @@ namespace Finna\Controller; use Exception; -use Finna\Form\Form; +use Finna\ReservationList\Form\Form as ReservationListForm; use Finna\ReservationList\ReservationListService; use Finna\View\Helper\Root\ReservationList; use Laminas\ServiceManager\ServiceLocatorInterface; @@ -302,7 +302,7 @@ public function placeOrderAction() if (!$listProperties || !$listProperties['Enabled']) { throw new \VuFind\Exception\Forbidden('No list properties found.'); } - $formId = Form::RESERVATION_LIST_REQUEST; + $formId = ReservationListForm::RESERVATION_LIST_REQUEST; $resourcesText = ''; $resourceIds = []; @@ -319,7 +319,7 @@ public function placeOrderAction() ->set('record_ids', $resourcesText) ->set('resourceIDs', $resourceIds); - $form = $this->getService(\Finna\Form\Form::class); + $form = $this->getService(\Finna\ReservationList\Form\Form::class); $form->setFormId(formId: $formId, prefill: $postRequest->toArray()); if (!$form->isEnabled()) { throw new \VuFind\Exception\Forbidden("Form '$formId' is disabled"); diff --git a/module/Finna/src/Finna/Form/Form.php b/module/Finna/src/Finna/Form/Form.php index 50997a68ece..3c30d9b1ffe 100644 --- a/module/Finna/src/Finna/Form/Form.php +++ b/module/Finna/src/Finna/Form/Form.php @@ -69,13 +69,6 @@ class Form extends \VuFind\Form\Form */ public const ARCHIVE_MATERIAL_REQUEST = 'ArchiveRequest'; - /** - * Reservation request form id. - * - * @var string - */ - public const RESERVATION_LIST_REQUEST = 'ReservationListRequest'; - /** * Handlers that are considered safe for transmitting information about the user * @@ -363,10 +356,6 @@ public function setReservationListRecipients(array $recipients): void */ public function getRecipient($postParams = null) { - // Always get recipients from postparams - if ($this->getFormId() === self::RESERVATION_LIST_REQUEST) { - return $this->reservationListRecipients; - } // Get recipient email address for feedback form from data source // configuration: if ($this->getFormId() === 'FeedbackRecord') { @@ -759,12 +748,7 @@ protected function getFormElements($config) $elements[$key] = ['type' => 'hidden', 'name' => $key, 'value' => null]; } } - // Add hidden fields for reservation list order form - if (self::RESERVATION_LIST_REQUEST === $this->getFormId()) { - $elements['rl_institution'] = ['type' => 'hidden', 'name' => 'rl_institution', 'value' => null]; - $elements['rl_list_identifier'] = ['type' => 'hidden', 'name' => 'rl_list_identifier', 'value' => null]; - $elements['rl_list_id'] = ['type' => 'hidden', 'name' => 'rl_list_id', 'value' => null]; - } + return $elements; } diff --git a/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php index 5ba2506863b..eb8d6fe5c52 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php +++ b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php @@ -30,10 +30,10 @@ namespace Finna\ReservationList\Connection; use Finna\Db\Entity\FinnaResourceListEntityInterface; +use Finna\ReservationList\Form\Form; use Laminas\Mvc\Controller\Plugin\Params; use Psr\Container\ContainerInterface; use VuFind\Db\Entity\UserEntityInterface; -use VuFind\Form\Form; use VuFind\Service\GetServiceTrait; /** diff --git a/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php b/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php index 5ee67bb1d82..62fb1325205 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ConnectionInterface.php @@ -30,9 +30,9 @@ namespace Finna\ReservationList\Connection; use Finna\Db\Entity\FinnaResourceListEntityInterface; +use Finna\ReservationList\Form\Form; use Laminas\Mvc\Controller\Plugin\Params; use VuFind\Db\Entity\UserEntityInterface; -use VuFind\Form\Form; /** * Reservation list connection plugin interface diff --git a/module/Finna/src/Finna/ReservationList/Connection/Disec.php b/module/Finna/src/Finna/ReservationList/Connection/Disec.php index 798b1a7470b..410f44685c3 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/Disec.php +++ b/module/Finna/src/Finna/ReservationList/Connection/Disec.php @@ -30,9 +30,9 @@ namespace Finna\ReservationList\Connection; use Finna\Db\Entity\FinnaResourceListEntityInterface; +use Finna\ReservationList\Form\Form; use Laminas\Mvc\Controller\Plugin\Params; use VuFind\Db\Entity\UserEntityInterface; -use VuFind\Form\Form; /** * Disec connection handler diff --git a/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php index a584d38d197..82309d79c0e 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php +++ b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php @@ -30,9 +30,9 @@ namespace Finna\ReservationList\Connection; use Finna\Db\Entity\FinnaResourceListEntityInterface; +use Finna\ReservationList\Form\Form; use Laminas\Mvc\Controller\Plugin\Params; use VuFind\Db\Entity\UserEntityInterface; -use VuFind\Form\Form; /** * FeedbackForm connection handler diff --git a/module/Finna/src/Finna/ReservationList/Form/Form.php b/module/Finna/src/Finna/ReservationList/Form/Form.php new file mode 100644 index 00000000000..13d38e845f6 --- /dev/null +++ b/module/Finna/src/Finna/ReservationList/Form/Form.php @@ -0,0 +1,102 @@ + + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ + +namespace Finna\ReservationList\Form; + +/** + * Configurable form. + * + * @category VuFind + * @package ReservationList + * @author Samuli Sillanpää + * @author Ere Maijala + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:controllers Wiki + */ +class Form extends \Finna\Form\Form +{ + /** + * Reservation request form id. + * + * @var string + */ + public const RESERVATION_LIST_REQUEST = 'ReservationListRequest'; + + /** + * Recipients for reservation lists + * + * @var array + */ + protected array $reservationListRecipients = []; + + /** + * Set recipients used in reservation lists as lists can have same configuration base + * but contain different recipients for each list + * + * @param array $recipients Array containing recipients [name, email] + * + * @return void + */ + public function setReservationListRecipients(array $recipients): void + { + $this->reservationListRecipients = $recipients; + } + + /** + * Return form recipient. + * + * @param array $postParams Posted form data + * + * @return array with name, email or null if not configured + */ + public function getRecipient($postParams = null) + { + return $this->reservationListRecipients; + } + + /** + * Get form elements + * + * @param array $config Form configuration + * + * @return array + */ + protected function getFormElements($config) + { + $elements = parent::getFormElements($config); + // Add hidden fields for reservation list order form + if (self::RESERVATION_LIST_REQUEST === $this->getFormId()) { + $elements['rl_institution'] = ['type' => 'hidden', 'name' => 'rl_institution', 'value' => null]; + $elements['rl_list_identifier'] = ['type' => 'hidden', 'name' => 'rl_list_identifier', 'value' => null]; + $elements['rl_list_id'] = ['type' => 'hidden', 'name' => 'rl_list_id', 'value' => null]; + } + return $elements; + } +} From ea5f3bcae2cf502ab3dd9a4c8327c910bec58b07 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:03:42 +0200 Subject: [PATCH 12/15] Removed unused parts of code --- local/config/finna/FeedbackForms.yaml.sample | 3 +-- module/Finna/src/Finna/Form/Form.php | 20 ------------------ .../src/Finna/ReservationList/Form/Form.php | 21 ++++++++----------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/local/config/finna/FeedbackForms.yaml.sample b/local/config/finna/FeedbackForms.yaml.sample index 43d6715fa3d..6d788e0ef8c 100644 --- a/local/config/finna/FeedbackForms.yaml.sample +++ b/local/config/finna/FeedbackForms.yaml.sample @@ -342,10 +342,9 @@ forms: settings: - [rows, 3] ReservationListRequest: - allowLocalOverride: true + allowLocalOverride: false title: ReservationList::form_title enabled: true - sendMethod: "email" onlyForLoggedUsers: true emailSubject: ReservationList::form_email_subject response: ReservationList::form_response diff --git a/module/Finna/src/Finna/Form/Form.php b/module/Finna/src/Finna/Form/Form.php index 3c30d9b1ffe..1c357bb61b4 100644 --- a/module/Finna/src/Finna/Form/Form.php +++ b/module/Finna/src/Finna/Form/Form.php @@ -154,13 +154,6 @@ class Form extends \VuFind\Form\Form */ protected $recordLoader = null; - /** - * Recipients for reservation lists - * - * @var array - */ - protected array $reservationListRecipients = []; - /** * Set form id * @@ -334,19 +327,6 @@ public function reportPatronId(): bool return (bool)($this->formConfig['includePatronId'] ?? false); } - /** - * Set recipients used in reservation lists as lists can have same configuration base - * but contain different recipients for each list - * - * @param array $recipients Array containing recipients [name, email] - * - * @return void - */ - public function setReservationListRecipients(array $recipients): void - { - $this->reservationListRecipients = $recipients; - } - /** * Return form recipient. * diff --git a/module/Finna/src/Finna/ReservationList/Form/Form.php b/module/Finna/src/Finna/ReservationList/Form/Form.php index 13d38e845f6..13515f6056a 100644 --- a/module/Finna/src/Finna/ReservationList/Form/Form.php +++ b/module/Finna/src/Finna/ReservationList/Form/Form.php @@ -54,23 +54,22 @@ class Form extends \Finna\Form\Form * * @var array */ - protected array $reservationListRecipients = []; + protected array $recipients = []; /** - * Set recipients used in reservation lists as lists can have same configuration base - * but contain different recipients for each list + * Set recipients * * @param array $recipients Array containing recipients [name, email] * * @return void */ - public function setReservationListRecipients(array $recipients): void + public function setRecipients(array $recipients): void { - $this->reservationListRecipients = $recipients; + $this->recipients = $recipients; } /** - * Return form recipient. + * Return form recipient. Name is in singular to override inherited methods * * @param array $postParams Posted form data * @@ -78,7 +77,7 @@ public function setReservationListRecipients(array $recipients): void */ public function getRecipient($postParams = null) { - return $this->reservationListRecipients; + return $this->recipients; } /** @@ -92,11 +91,9 @@ protected function getFormElements($config) { $elements = parent::getFormElements($config); // Add hidden fields for reservation list order form - if (self::RESERVATION_LIST_REQUEST === $this->getFormId()) { - $elements['rl_institution'] = ['type' => 'hidden', 'name' => 'rl_institution', 'value' => null]; - $elements['rl_list_identifier'] = ['type' => 'hidden', 'name' => 'rl_list_identifier', 'value' => null]; - $elements['rl_list_id'] = ['type' => 'hidden', 'name' => 'rl_list_id', 'value' => null]; - } + $elements['rl_institution'] = ['type' => 'hidden', 'name' => 'rl_institution', 'value' => null]; + $elements['rl_list_identifier'] = ['type' => 'hidden', 'name' => 'rl_list_identifier', 'value' => null]; + $elements['rl_list_id'] = ['type' => 'hidden', 'name' => 'rl_list_id', 'value' => null]; return $elements; } } From 94fa86a6c1f23032fba28d29cee55f8017e9f5ed Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:30:36 +0200 Subject: [PATCH 13/15] Readded in_process as it is a plausible state for order, adjusted comments --- local/languages/finna/ReservationList/en-gb.ini | 1 + local/languages/finna/ReservationList/fi.ini | 1 + local/languages/finna/ReservationList/se.ini | 1 + local/languages/finna/ReservationList/sv.ini | 1 + .../Finna/ReservationList/Connection/AbstractBase.php | 6 +++++- .../src/Finna/ReservationList/Connection/Disec.php | 6 +++++- .../Finna/ReservationList/Connection/FeedbackForm.php | 10 +++++++--- .../Connection/ReservationListStatus.php | 1 + 8 files changed, 22 insertions(+), 5 deletions(-) diff --git a/local/languages/finna/ReservationList/en-gb.ini b/local/languages/finna/ReservationList/en-gb.ini index abef4c38fdf..309389f5db2 100644 --- a/local/languages/finna/ReservationList/en-gb.ini +++ b/local/languages/finna/ReservationList/en-gb.ini @@ -32,6 +32,7 @@ Select = "Select" ; List statuses: status_unknown = "" status_delivered = "Delivered" +status_in_process = "In process" status_canceled = "Cancelled" status_on_loan = "On Loan" status_returned = "Returned" diff --git a/local/languages/finna/ReservationList/fi.ini b/local/languages/finna/ReservationList/fi.ini index 37ed7eb459e..8280e3da438 100644 --- a/local/languages/finna/ReservationList/fi.ini +++ b/local/languages/finna/ReservationList/fi.ini @@ -32,6 +32,7 @@ Select = "Valitse" ; List statuses: status_unknown = "" status_delivered = "Toimitettu" +status_in_process = "Käsittelyssä" status_canceled = "Peruutettu" status_on_loan = "Lainassa" status_returned = "Palautettu" diff --git a/local/languages/finna/ReservationList/se.ini b/local/languages/finna/ReservationList/se.ini index 620e8f145a5..914edf2496a 100644 --- a/local/languages/finna/ReservationList/se.ini +++ b/local/languages/finna/ReservationList/se.ini @@ -32,6 +32,7 @@ Select = "" ; List statuses: status_unknown = "" status_delivered = "" +status_in_process = "" status_canceled = "" status_on_loan = "" status_returned = "" diff --git a/local/languages/finna/ReservationList/sv.ini b/local/languages/finna/ReservationList/sv.ini index cf88627e577..b8c86ad7914 100644 --- a/local/languages/finna/ReservationList/sv.ini +++ b/local/languages/finna/ReservationList/sv.ini @@ -32,6 +32,7 @@ Select = "Välj" ; List statuses: status_unknown = "" status_delivered = "Levererad" +status_in_process = "Behandlas" status_canceled = "Annullerad" status_on_loan = "Utlånad" status_returned = "Returnerad" diff --git a/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php index eb8d6fe5c52..e893641228f 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php +++ b/module/Finna/src/Finna/ReservationList/Connection/AbstractBase.php @@ -67,7 +67,11 @@ public function __construct(ContainerInterface $serviceLocator) * @param UserEntityInterface $user User entity * @param Form $form Form posted when submitting the order * - * @return array [external_id: Id in external service or null, success: true or false] + * @return array [ + * external_id: Id in external service or null, + * success: true or false, + * pickup_date: date for preferred pickup + * ] */ abstract public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array; diff --git a/module/Finna/src/Finna/ReservationList/Connection/Disec.php b/module/Finna/src/Finna/ReservationList/Connection/Disec.php index 410f44685c3..4cab3ae14e4 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/Disec.php +++ b/module/Finna/src/Finna/ReservationList/Connection/Disec.php @@ -83,7 +83,11 @@ class Disec extends AbstractBase * @param UserEntityInterface $user User entity * @param Form $form Form posted when submitting the order * - * @return array [external_id: Id in external service or null, success: true or false] + * @return array [ + * external_id: Id in external service or null, + * success: true or false, + * pickup_date: date for preferred pickup + * ] */ public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array { diff --git a/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php index 82309d79c0e..7615856eca4 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php +++ b/module/Finna/src/Finna/ReservationList/Connection/FeedbackForm.php @@ -59,12 +59,16 @@ class FeedbackForm extends AbstractBase * @param UserEntityInterface $user User entity * @param Form $form Form posted when submitting the order * - * @return array [external_id: Id in external service or null, success: true or false] + * @return array [ + * external_id: Id in external service or null, + * success: true or false, + * pickup_date: date for preferred pickup + * ] */ public function placeOrder(Params $params, UserEntityInterface $user, Form $form = null): array { - // Assign external recipients as lists can contain different recipients even if form base is the same - $form->setReservationListRecipients($this->recipients); + // Lists use list specific recipients for orders + $form->setRecipients($this->recipients); $result = $form->getPrimaryHandler()->handle($form, $params, $user); return [ 'success' => $result, diff --git a/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php b/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php index b0562d3426f..d974ab7ce06 100644 --- a/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php +++ b/module/Finna/src/Finna/ReservationList/Connection/ReservationListStatus.php @@ -42,6 +42,7 @@ enum ReservationListStatus: string { case UNKNOWN = 'unknown'; case DELIVERED = 'delivered'; + case IN_PROCESS = 'in_process'; case CANCELLED = 'cancelled'; case ON_LOAN = 'on_loan'; case RETURNED = 'returned'; From 030f4667725e8c5353bded89b2de70da826106ce Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:42:16 +0200 Subject: [PATCH 14/15] Revert php versions to 8 --- module/Finna/src/Finna/AjaxHandler/ReservationList.php | 2 +- module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php | 2 +- .../src/Finna/Controller/ReservationListControllerFactory.php | 2 +- .../src/Finna/Db/Entity/FinnaResourceListEntityInterface.php | 2 +- .../Db/Entity/FinnaResourceListResourceEntityInterface.php | 2 +- module/Finna/src/Finna/Db/Row/FinnaResourceList.php | 2 +- module/Finna/src/Finna/Db/Row/FinnaResourceListResource.php | 2 +- module/Finna/src/Finna/Db/Service/FinnaResourceListService.php | 2 +- module/Finna/src/Finna/Db/Table/FinnaResourceList.php | 2 +- module/Finna/src/Finna/Db/Table/FinnaResourceListResource.php | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationList.php b/module/Finna/src/Finna/AjaxHandler/ReservationList.php index e9ea3cbf1eb..1a9319f39a0 100644 --- a/module/Finna/src/Finna/AjaxHandler/ReservationList.php +++ b/module/Finna/src/Finna/AjaxHandler/ReservationList.php @@ -3,7 +3,7 @@ /** * Reservation list ajax handler * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php b/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php index 8f7187ef1b1..ac8fe44228a 100644 --- a/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php +++ b/module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php @@ -3,7 +3,7 @@ /** * Reservation list ajax handler factory * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/Controller/ReservationListControllerFactory.php b/module/Finna/src/Finna/Controller/ReservationListControllerFactory.php index 668e8876c2c..d73e6019da4 100644 --- a/module/Finna/src/Finna/Controller/ReservationListControllerFactory.php +++ b/module/Finna/src/Finna/Controller/ReservationListControllerFactory.php @@ -3,7 +3,7 @@ /** * Reservation list controller factory. * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php b/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php index 4bce202e821..23cf0213d74 100644 --- a/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php +++ b/module/Finna/src/Finna/Db/Entity/FinnaResourceListEntityInterface.php @@ -3,7 +3,7 @@ /** * Finna resource list entity interface * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/Db/Entity/FinnaResourceListResourceEntityInterface.php b/module/Finna/src/Finna/Db/Entity/FinnaResourceListResourceEntityInterface.php index 18076f085f0..e74caf274cd 100644 --- a/module/Finna/src/Finna/Db/Entity/FinnaResourceListResourceEntityInterface.php +++ b/module/Finna/src/Finna/Db/Entity/FinnaResourceListResourceEntityInterface.php @@ -3,7 +3,7 @@ /** * Finna resource list resource entity interface. * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/Db/Row/FinnaResourceList.php b/module/Finna/src/Finna/Db/Row/FinnaResourceList.php index 031ad66f91a..ecbad659be4 100644 --- a/module/Finna/src/Finna/Db/Row/FinnaResourceList.php +++ b/module/Finna/src/Finna/Db/Row/FinnaResourceList.php @@ -3,7 +3,7 @@ /** * Row Definition for finna_resource_list * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/Db/Row/FinnaResourceListResource.php b/module/Finna/src/Finna/Db/Row/FinnaResourceListResource.php index 2f0242adea7..80cabb80e07 100644 --- a/module/Finna/src/Finna/Db/Row/FinnaResourceListResource.php +++ b/module/Finna/src/Finna/Db/Row/FinnaResourceListResource.php @@ -3,7 +3,7 @@ /** * Table Definition for finna_resource_list_resource * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/Db/Service/FinnaResourceListService.php b/module/Finna/src/Finna/Db/Service/FinnaResourceListService.php index df73ca19cb1..8d6962bf987 100644 --- a/module/Finna/src/Finna/Db/Service/FinnaResourceListService.php +++ b/module/Finna/src/Finna/Db/Service/FinnaResourceListService.php @@ -3,7 +3,7 @@ /** * Resource list service * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * diff --git a/module/Finna/src/Finna/Db/Table/FinnaResourceList.php b/module/Finna/src/Finna/Db/Table/FinnaResourceList.php index f820d358d1a..6678c10238f 100644 --- a/module/Finna/src/Finna/Db/Table/FinnaResourceList.php +++ b/module/Finna/src/Finna/Db/Table/FinnaResourceList.php @@ -3,7 +3,7 @@ /** * Table Definition for finna_resource_list * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) Villanova University 2024. * Copyright (C) The National Library of Finland 2024. diff --git a/module/Finna/src/Finna/Db/Table/FinnaResourceListResource.php b/module/Finna/src/Finna/Db/Table/FinnaResourceListResource.php index 8d16a110a39..c073b589a4c 100644 --- a/module/Finna/src/Finna/Db/Table/FinnaResourceListResource.php +++ b/module/Finna/src/Finna/Db/Table/FinnaResourceListResource.php @@ -3,7 +3,7 @@ /** * Table Definition for finna_resource_list_resource * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) The National Library of Finland 2024. * From 7c9b98f4dff8326e09b51e03b45b3ba1dedef983 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:42:26 +0200 Subject: [PATCH 15/15] And also this one --- module/Finna/src/Finna/Search/ReservationList/Options.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/Finna/src/Finna/Search/ReservationList/Options.php b/module/Finna/src/Finna/Search/ReservationList/Options.php index 79e7748d894..708ae93bc11 100644 --- a/module/Finna/src/Finna/Search/ReservationList/Options.php +++ b/module/Finna/src/Finna/Search/ReservationList/Options.php @@ -3,7 +3,7 @@ /** * Reservation List Options * - * PHP version 8.1 + * PHP version 8 * * Copyright (C) National Library of Finland 2024. *