Browse Source

added doi to logging also now log failed requests

9.x-1.0
Paul Pound 7 years ago
parent
commit
8a2e21c6b7
  1. 1
      includes/db.inc
  2. 7
      includes/form.inc
  3. 33
      includes/relais.inc
  4. 8
      upei_roblib_ill.install
  5. 24
      upei_roblib_ill.module

1
includes/db.inc

@ -26,6 +26,7 @@ function upei_roblib_ill_log_request($request, $response) {
//'patron_email' => $request['DeliveryAddress']['DeliveryAddress'], //'patron_email' => $request['DeliveryAddress']['DeliveryAddress'],
'notes' => isset($request['DeliveryAddress']['notes']) ? $request['DeliveryAddress']['notes'] : '', 'notes' => isset($request['DeliveryAddress']['notes']) ? $request['DeliveryAddress']['notes'] : '',
'genre' => isset($request['BibliographicInfo']['Genre']) ? $request['BibliographicInfo']['Genre'] : '', 'genre' => isset($request['BibliographicInfo']['Genre']) ? $request['BibliographicInfo']['Genre'] : '',
'doi' => isset($request['BibliographicInfo']['AdditionalNumbers']) ? $request['BibliographicInfo']['AdditionalNumbers'] : '',
'author' => isset($request['BibliographicInfo']['Author']) ? $request['BibliographicInfo']['Author'] : '', 'author' => isset($request['BibliographicInfo']['Author']) ? $request['BibliographicInfo']['Author'] : '',
'citation_date' => isset($request['BibliographicInfo']['Date']) ? $request['BibliographicInfo']['Date'] : '', 'citation_date' => isset($request['BibliographicInfo']['Date']) ? $request['BibliographicInfo']['Date'] : '',
'title' => isset($request['BibliographicInfo']['Title']) ? $request['BibliographicInfo']['Title'] : '', 'title' => isset($request['BibliographicInfo']['Title']) ? $request['BibliographicInfo']['Title'] : '',

7
includes/form.inc

@ -43,6 +43,11 @@ function upei_roblib_ill_form_validate($form, &$form_state) {
if (is_array($aid) && isset($aid['Problem']['Message'])) { if (is_array($aid) && isset($aid['Problem']['Message'])) {
form_set_error('Surname', $aid['Problem']['Message']); form_set_error('Surname', $aid['Problem']['Message']);
form_set_error('campus_id', ''); form_set_error('campus_id', '');
// Log invalid requests, we need to build the full array here to log it, even though we won't send it yet as auth has failed.
$form_state['storage']['upei_roblib_ill_auth_form'] = $form_state['values'];
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
$arr = upei_roblib_ill_build_relais_arr($form_state);
upei_roblib_ill_log_request($arr, $aid);
} }
else { else {
$form_state['storage']['aid'] = $aid; $form_state['storage']['aid'] = $aid;
@ -95,7 +100,7 @@ function upei_roblib_ill_form_submit($form, &$form_state) {
function upei_roblib_ill_form_redirect() { function upei_roblib_ill_form_redirect() {
//TODO turn this into a drupal render array //TODO turn this into a drupal render array
//TODO phone number, email etc. could be variables read from the database. //TODO phone number, email etc. could be variables read from the database.
$std_message = "<div class='upei-roblib-ill-message'>To contact the department about this request, you can send a message to <a href='mailto:ill@upei.ca'>ill@upei.ca</a> or $std_message = "<div class='upei-roblib-ill-email'>A message including the Request ID has been sent to your UPEI email address.</div><div class='upei-roblib-ill-message'>To contact the department about this request, you can send a message to <a href='mailto:ill@upei.ca'>ill@upei.ca</a> or
call 902-566-0445</div>"; call 902-566-0445</div>";
return "<div class='upei-roblib-ill-relais-message'>" . $_GET['message'] . '</div>' . $std_message; return "<div class='upei-roblib-ill-relais-message'>" . $_GET['message'] . '</div>' . $std_message;
} }

33
includes/relais.inc

@ -14,27 +14,21 @@ function upei_roblib_ill_get_pub_type($genre) {
return 'J'; return 'J';
} }
} }
/** /**
* Submit an ILL AddRequest to relais. * Submit an ILL AddRequest to relais.
*
* @param array $form_state * @param array $form_state
* A drupal form_state array * A drupal form_state array
* @param string $aid * @param string $aid
* A relais authentication id (token) * A relais authentication id (token)
* @return array|mixed
*/ */
function upei_roblib_ill_add_request($form_state, $aid) { function upei_roblib_ill_add_request($form_state, $aid) {
module_load_include('inc', 'upei_roblib_ill', 'includes/db'); module_load_include('inc', 'upei_roblib_ill', 'includes/db');
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities'); module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add'); $url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add');
$relais_arr = array( $relais_arr = upei_roblib_ill_build_relais_arr($form_state);
"SupplyingLibrarySymbol" => variable_get('upei_roblib_ill_library_symbol','PCU'),
);
$relais_arr['BibliographicInfo'] = upei_roblib_ill_clean_array($form_state['storage']['upei_roblib_ill_request_form']);
$relais_arr['DeliveryAddress'] = upei_roblib_ill_clean_array($form_state['storage']['upei_roblib_ill_auth_form']);
$request_info = upei_roblib_ill_request_info_array($relais_arr['BibliographicInfo'], $form_state['values']['notes']);
$relais_arr['RequestInfo'] = $request_info;
$relais_arr['PublisherInfo']['PublicationDate'] = isset($form_state['storage']['upei_roblib_ill_request_form']['Date']) ?
$form_state['storage']['upei_roblib_ill_request_form']['Date'] : '';
$relais_arr['PublisherInfo']['PublicationType'] = upei_roblib_ill_get_pub_type($form_state['storage']['upei_roblib_ill_request_form']['Genre']);
$relais_json = json_encode($relais_arr); $relais_json = json_encode($relais_arr);
$options = array( $options = array(
'method' => 'POST', 'method' => 'POST',
@ -59,6 +53,25 @@ function upei_roblib_ill_add_request($form_state, $aid) {
return $response_arr; return $response_arr;
} }
/**
* @param $form_state
* @return array
*/
function upei_roblib_ill_build_relais_arr($form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$relais_arr = array(
"SupplyingLibrarySymbol" => variable_get('upei_roblib_ill_library_symbol','PCU'),
);
$relais_arr['BibliographicInfo'] = upei_roblib_ill_clean_array($form_state['storage']['upei_roblib_ill_request_form']);
$relais_arr['DeliveryAddress'] = upei_roblib_ill_clean_array($form_state['storage']['upei_roblib_ill_auth_form']);
$request_info = upei_roblib_ill_request_info_array($relais_arr['BibliographicInfo'], $form_state['values']['notes']);
$relais_arr['RequestInfo'] = $request_info;
$relais_arr['PublisherInfo']['PublicationDate'] = isset($form_state['storage']['upei_roblib_ill_request_form']['Date']) ?
$form_state['storage']['upei_roblib_ill_request_form']['Date'] : '';
$relais_arr['PublisherInfo']['PublicationType'] = upei_roblib_ill_get_pub_type($form_state['storage']['upei_roblib_ill_request_form']['Genre']);
return $relais_arr;
}
/** /**
* Request an aid from Relais. * Request an aid from Relais.
* @param string $barcode * @param string $barcode

8
upei_roblib_ill.install

@ -41,7 +41,7 @@ function upei_roblib_ill_schema() {
'description' => 'The email address of the user that submitted the request', 'description' => 'The email address of the user that submitted the request',
'type' => 'varchar', 'type' => 'varchar',
'length' => '255', 'length' => '255',
'not null' => TRUE, 'not null' => FALSE,
), ),
'patron_lastname' => array( 'patron_lastname' => array(
'description' => 'Lastname of the user that submitted the request', 'description' => 'Lastname of the user that submitted the request',
@ -133,6 +133,12 @@ function upei_roblib_ill_schema() {
'length' => '30', 'length' => '30',
'not null' => TRUE, 'not null' => TRUE,
), ),
'doi' => array(
'description' => 'The DOI',
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'relais_request_id' => array( 'relais_request_id' => array(
'description' => 'The request id stored in the Relais datbabase', 'description' => 'The request id stored in the Relais datbabase',
'type' => 'varchar', 'type' => 'varchar',

24
upei_roblib_ill.module

@ -36,6 +36,13 @@ function upei_roblib_ill_menu() {
return $items; return $items;
} }
/**
* Get the metadata associated with this DOI.
*
* @param $form
* @param $form_state
* @return array
*/
function upei_roblib_ill_doi_callback($form, &$form_state) { function upei_roblib_ill_doi_callback($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/doi'); module_load_include('inc', 'upei_roblib_ill', 'includes/doi');
$form = upei_roblib_ill_doi_get_data($form, $form_state['values']['doi']); $form = upei_roblib_ill_doi_get_data($form, $form_state['values']['doi']);
@ -370,6 +377,23 @@ function upei_roblib_ill_views_data() {
'handler' => 'views_handler_argument_string', 'handler' => 'views_handler_argument_string',
), ),
); );
$data['upei_roblib_ill_request']['doi'] = array(
'title' => t('DOI'),
'help' => t('DOI.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['relais_request_id'] = array( $data['upei_roblib_ill_request']['relais_request_id'] = array(
'title' => t('The Relais request id'), 'title' => t('The Relais request id'),
'help' => t('The Relais request id.'), 'help' => t('The Relais request id.'),

Loading…
Cancel
Save