The libraries interlibrary loan form module
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.4 KiB

<?php
/**
* @file
* functions for database access.
*/
use RapidIll\InsertRequest;
/**
* Log an ILL request
*
* @param \RapidIll\InsertRequest $request
* The request sent to RapidILL as an InsertRequest object.
* @param array|string $response
* The response from RapidILL or an error message.
*/
function upei_roblib_ill_log_request(InsertRequest $request, $response) {
$soap_data = $request->toSoapArray();
$time_submitted = time();
$relais_message = is_array($response) ? (isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : ($response['Problem']['Message'] ?? '')) : (string) $response;
$patron_firstname = '';
$patron_lastname = '';
if (!empty($soap_data['PatronName'])) {
$parts = explode(' ', $soap_data['PatronName'], 2);
$patron_firstname = trim($parts[0] ?? '');
$patron_lastname = trim($parts[1] ?? '');
}
$connection = \Drupal::service('database');
try {
$connection->insert('upei_roblib_ill_request')
->fields([
'patron_id' => $soap_data['PatronId'] ?? '',
'patron_firstname' => $patron_firstname,
'patron_lastname' => $patron_lastname,
'patron_type' => '',
'patron_department' => $soap_data['PatronDepartment'] ?? '',
'patron_email' => $soap_data['PatronEmail'] ?? '',
'notes' => $soap_data['PatronNotes'] ?? '',
'genre' => $soap_data['RapidRequestType'] ?? '',
'doi' => '',
'author' => $soap_data['ArticleAuthor'] ?? '',
'citation_date' => $soap_data['PatronJournalYear'] ?? '',
'title' => $soap_data['PatronJournalTitle'] ?? '',
'atitle' => $soap_data['ArticleTitle'] ?? '',
'issn' => $soap_data['SuggestedIssns']['string'][0] ?? '',
'isbn' => $soap_data['SuggestedIsbns']['string'][0] ?? '',
'article_author' => $soap_data['ArticleAuthor'] ?? '',
'volume' => $soap_data['JournalVol'] ?? '',
'issue' => $soap_data['JournalIssue'] ?? '',
'pages_requested' => $soap_data['ArticlePages'] ?? '',
'time_submitted' => $time_submitted,
'relais_request_id' => is_array($response) && isset($response['RequestNumber']) ? $response['RequestNumber'] : '-1',
'relais_message' => substr($relais_message, 0, 254),
])->execute();
} catch (Exception $e) {
\Drupal::logger('upei_roblib_ill')->error('Error logging ILL request @msg',
array(
'@msg' => $e->getMessage(),
));
}
}