Skip to content
Snippets Groups Projects
Commit c3ac8bc2 authored by Michael Birkner's avatar Michael Birkner Committed by Robert Lange
Browse files

Using request-options API for requestable indicator. Jira VUFIND-1299.

parent dcfe005a
No related merge requests found
...@@ -75,38 +75,6 @@ expiryDate = ...@@ -75,38 +75,6 @@ expiryDate =
purgeDate = purgeDate =
[FulfillmentUnits]
; Specify the association of fulfillment units and its locations. Take the codes from:
; Alma Configuration -> Fulfillment -> Fulfillment Units -> [Choose Fulfillment Unit] -> Fulfillment Unit Locations.
; Tip: Export the list from Alma as Excel and use the CONCATENATE() formula to generate this list.
; Format: FULFILLMENT_UNIT_CODE[] = LOCATION_CODE
; Example:
; STACKS[] = stack1
; STACKS[] = stack2
; STACKS[] = stack3
; LIMITED[] = periodicalroom
; LIMITED[] = musicrefs
; SHORTLOAN[] = office1
; SHORTLOAN[] = office2
[Requestable]
; Specify for which combination of user group and fulfillment unit (see above) the request link
; should be displayed (who is allowed to request what). Define every combination of fulfillment unit
; and user group and assign "N" for "No, not requestable for this user group" or "Y" for "Yes, is
; requestable for this user group". You will find the user group codes here:
; Alma Configuration -> User Management -> User Groups
; Format: FULFILLMENT_UNIT_CODE[USER_GROUP_CODE] = N
; Example:
; STACKS[STAFF] = Y
; STACKS[STUDENT] = Y
; STACKS[GUEST] = Y
; LIMITED[STAFF] = Y
; LIMITED[STUDENT] = N
; LIMITED[GUEST] = N
; SHORTLOAN[STAFF] = Y
; SHORTLOAN[STUDENT] = Y
; SHORTLOAN[GUEST] = N
[Webhook] [Webhook]
; The webhook secret. This must be the same value that was added to the Alma webhook configuration as a secret. ; The webhook secret. This must be the same value that was added to the Alma webhook configuration as a secret.
secret = YOUR_WEBHOOK_SECRET_FROM_ALMA secret = YOUR_WEBHOOK_SECRET_FROM_ALMA
......
...@@ -241,26 +241,14 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface ...@@ -241,26 +241,14 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
*/ */
public function getHolding($id, array $patron = null) public function getHolding($id, array $patron = null)
{ {
// Get config data:
$fulfillementUnits = $this->config['FulfillmentUnits'] ?? null;
$requestableConfig = $this->config['Requestable'] ?? null;
$results = []; $results = [];
$copyCount = 0; $copyCount = 0;
$username = $patron['cat_username'] ?? null;
$bibPath = '/bibs/' . urlencode($id) . '/holdings'; $bibPath = '/bibs/' . urlencode($id) . '/holdings';
if ($holdings = $this->makeRequest($bibPath)) { if ($holdings = $this->makeRequest($bibPath)) {
foreach ($holdings->holding as $holding) { foreach ($holdings->holding as $holding) {
$holdingId = (string)$holding->holding_id; $holdingId = (string)$holding->holding_id;
$locationCode = (string)$holding->location; $locationCode = (string)$holding->location;
$addLink = false;
if ($fulfillementUnits != null && $requestableConfig != null) {
$addLink = $this->requestsAllowed(
$fulfillementUnits,
$locationCode,
$requestableConfig,
$patron
);
}
$itemPath = $bibPath . '/' . urlencode($holdingId) . '/items'; $itemPath = $bibPath . '/' . urlencode($holdingId) . '/items';
if ($currentItems = $this->makeRequest($itemPath)) { if ($currentItems = $this->makeRequest($itemPath)) {
...@@ -299,6 +287,36 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface ...@@ -299,6 +287,36 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
$duedate = $this->parseDate((string)$loan->due_date); $duedate = $this->parseDate((string)$loan->due_date);
} }
// Calculate request options if a user is logged-in
if ($username) {
// Call the request-options API for the logged-in user
$requestOptionsPath = '/bibs/' . urlencode($id)
. '/holdings/' . urlencode($holdingId) . '/items/'
. urlencode($itemId) . '/request-options?user_id='
. urlencode($username);
// Make the API request
$requestOptions = $this->makeRequest(
$requestOptionsPath
);
// Get all possible request types from the API answer
$requestTypes = $requestOptions->xpath(
'/request_options/request_option//type'
);
// Add all allowed request types to an array
$requestTypesArr = [];
foreach ($requestTypes as $requestType) {
$requestTypesArr[] = (string)$requestType;
}
// If HOLD is an allowed request type, add the link for
// placing a hold
$addLink = in_array('HOLD', $requestTypesArr);
}
$results[] = [ $results[] = [
'id' => $id, 'id' => $id,
'source' => 'Solr', 'source' => 'Solr',
...@@ -317,7 +335,7 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface ...@@ -317,7 +335,7 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
'item_notes' => $itemNotes, 'item_notes' => $itemNotes,
'item_id' => $itemId, 'item_id' => $itemId,
'holding_id' => $holdingId, 'holding_id' => $holdingId,
'addLink' => $addLink, 'addLink' => $addLink ?? false,
// For Alma title-level hold requests // For Alma title-level hold requests
'description' => $description 'description' => $description
]; ];
...@@ -329,64 +347,6 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface ...@@ -329,64 +347,6 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
return $results; return $results;
} }
/**
* Check if the user is allowed to place requests for an Alma fulfillment
* unit in general. We check for blocks on the patron account that could
* block a request in getRequestBlocks().
*
* @param array $fulfillementUnits An array of fulfillment units and associated
* locations from Alma.ini (see section
* [FulfillmentUnits])
* @param string $locationCode The location code of the holding to be
* checked
* @param array $requestableConfig An array of fulfillment units and associated
* patron groups and their request policy from
* Alma.ini (see section [Requestable])
* @param array $patron An array with the patron details (username
* and password)
*
* @return boolean true if the the patron is allowed to place
* requests on holdings of this fulfillment
* unit, false otherwise.
* @author Michael Birkner
*/
protected function requestsAllowed(
$fulfillementUnits,
$locationCode,
$requestableConfig,
$patron
) {
$requestsAllowed = false;
// Get user group code
$cacheId = 'alma|user|' . $patron['cat_username'] . '|group_code';
$userGroupCode = $this->getCachedData($cacheId);
if ($userGroupCode === null) {
$profile = $this->getMyProfile($patron);
$userGroupCode = (string)$profile['group_code'];
}
// Get the fulfillment unit of the location.
$locationFulfillmentUnit = $this->getFulfillmentUnitByLocation(
$locationCode,
$fulfillementUnits
);
// Check if the group of the currently logged in user is allowed to place
// requests on items belonging to current fulfillment unit
if (($locationFulfillmentUnit != null && !empty($locationFulfillmentUnit))
&& ($userGroupCode != null && !empty($userGroupCode))
) {
$requestsAllowed = false;
if ($requestableConfig[$locationFulfillmentUnit][$userGroupCode] == 'Y'
) {
$requestsAllowed = true;
}
}
return $requestsAllowed;
}
/** /**
* Check for request blocks. * Check for request blocks.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment