Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions local/config/finna/ReservationList.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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:
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
# Database: Default connection, orders handled with sending forms
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
# handler: email [Optional] Default handler email, other values found in FeedbackForms.yaml primary handlers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miten tämä suhteutuu FeedbackForms.yaml:n asetuksiin? Jos tähän laittaa vaikka api, niin mitä asetuksia se käyttää? Olisiko parempi jättää lähetystapa formin puolella määriteltäväksi niin, että lähetys feedbackforms:n kautta käyttää oikeasti lomaketta eikä vain handleria? Muussa tapauksessa olisi parempi irrottaa handlerit sieltä ReservationList:n connectioneiksi.

# 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::
#
Expand Down
12 changes: 12 additions & 0 deletions local/languages/finna/ReservationList/en-gb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
status_replied = "Replied"
status_removed_item = "Item removed"
status_loaned = "Loaned"
status_returned = "Returned"
status_renewed = "Renewed"
12 changes: 12 additions & 0 deletions local/languages/finna/ReservationList/fi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 12 additions & 0 deletions local/languages/finna/ReservationList/se.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
12 changes: 12 additions & 0 deletions local/languages/finna/ReservationList/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
status_replied = "Besvarad"
status_removed_item = "Objekt borttaget"
status_loaned = "Lånad"
status_returned = "Returnerad"
status_renewed = "Förnyad"
5 changes: 5 additions & 0 deletions module/Finna/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -491,6 +492,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' =>
Expand Down Expand Up @@ -531,6 +534,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',
Expand Down Expand Up @@ -763,6 +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 */ ],
'recommend' => [
'factories' => [
'VuFind\Recommend\CollectionSideFacets' => 'Finna\Recommend\Factory::getCollectionSideFacets',
Expand Down
1 change: 1 addition & 0 deletions module/Finna/sql/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `resource_list_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
Expand Down
112 changes: 112 additions & 0 deletions module/Finna/src/Finna/AjaxHandler/ReservationList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

/**
* Reservation list ajax handler
*
* PHP version 8.1
*
* Copyright (C) The National Library of Finland 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package AjaxHandler
* @author Juha Luoma <juha.luoma@helsinki.fi>
* @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 <juha.luoma@helsinki.fi>
* @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 = '';
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
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($result);
break;
default:
break;
}
return $this->formatResponse($result);
}
}
75 changes: 75 additions & 0 deletions module/Finna/src/Finna/AjaxHandler/ReservationListFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Reservation list ajax handler factory
*
* PHP version 8.1
*
* Copyright (C) The National Library of Finland 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package AjaxHandler
* @author Juha Luoma <juha.luoma@helsinki.fi>
* @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 <juha.luoma@helsinki.fi>
* @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),
);
}
}
32 changes: 14 additions & 18 deletions module/Finna/src/Finna/Controller/ReservationListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -333,13 +329,13 @@ 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()),
'email' => $user->getEmail(),
'firstName' => $user->getFirstname(),
'lastName' => $user->getLastname(),
'email' => $user->getEmail(),
]
);
return $view;
Expand All @@ -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);
EreMaijala marked this conversation as resolved.
Show resolved Hide resolved
$this->reservationListService->setListOrdered($user, $list, $request->getPost());
$this->flashMessenger()->addSuccessMessage($form->getSubmitResponse());
return $this->getRefreshResponse();
Expand Down
Loading
Loading