From 8a2e21c6b7b4a9945324529835aee4bb408fe896 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Tue, 23 May 2017 11:40:30 -0300 Subject: [PATCH] added doi to logging also now log failed requests --- includes/db.inc | 1 + includes/form.inc | 7 ++++++- includes/relais.inc | 33 +++++++++++++++++++++++---------- upei_roblib_ill.install | 8 +++++++- upei_roblib_ill.module | 24 ++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/includes/db.inc b/includes/db.inc index 201f77a..41f9c1f 100644 --- a/includes/db.inc +++ b/includes/db.inc @@ -26,6 +26,7 @@ function upei_roblib_ill_log_request($request, $response) { //'patron_email' => $request['DeliveryAddress']['DeliveryAddress'], 'notes' => isset($request['DeliveryAddress']['notes']) ? $request['DeliveryAddress']['notes'] : '', 'genre' => isset($request['BibliographicInfo']['Genre']) ? $request['BibliographicInfo']['Genre'] : '', + 'doi' => isset($request['BibliographicInfo']['AdditionalNumbers']) ? $request['BibliographicInfo']['AdditionalNumbers'] : '', 'author' => isset($request['BibliographicInfo']['Author']) ? $request['BibliographicInfo']['Author'] : '', 'citation_date' => isset($request['BibliographicInfo']['Date']) ? $request['BibliographicInfo']['Date'] : '', 'title' => isset($request['BibliographicInfo']['Title']) ? $request['BibliographicInfo']['Title'] : '', diff --git a/includes/form.inc b/includes/form.inc index f65d1d4..8fff829 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -43,6 +43,11 @@ function upei_roblib_ill_form_validate($form, &$form_state) { if (is_array($aid) && isset($aid['Problem']['Message'])) { form_set_error('Surname', $aid['Problem']['Message']); 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 { $form_state['storage']['aid'] = $aid; @@ -95,7 +100,7 @@ function upei_roblib_ill_form_submit($form, &$form_state) { function upei_roblib_ill_form_redirect() { //TODO turn this into a drupal render array //TODO phone number, email etc. could be variables read from the database. - $std_message = "
To contact the department about this request, you can send a message to ill@upei.ca or + $std_message = "
To contact the department about this request, you can send a message to ill@upei.ca or call 902-566-0445
"; return "
" . $_GET['message'] . '
' . $std_message; } diff --git a/includes/relais.inc b/includes/relais.inc index 3286f04..b86da02 100644 --- a/includes/relais.inc +++ b/includes/relais.inc @@ -14,27 +14,21 @@ function upei_roblib_ill_get_pub_type($genre) { return 'J'; } } + /** * Submit an ILL AddRequest to relais. + * * @param array $form_state * A drupal form_state array * @param string $aid * A relais authentication id (token) + * @return array|mixed */ 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/utilities'); $url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add'); - $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']); + $relais_arr = upei_roblib_ill_build_relais_arr($form_state); $relais_json = json_encode($relais_arr); $options = array( 'method' => 'POST', @@ -59,6 +53,25 @@ function upei_roblib_ill_add_request($form_state, $aid) { 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. * @param string $barcode diff --git a/upei_roblib_ill.install b/upei_roblib_ill.install index 556da79..120c9c2 100644 --- a/upei_roblib_ill.install +++ b/upei_roblib_ill.install @@ -41,7 +41,7 @@ function upei_roblib_ill_schema() { 'description' => 'The email address of the user that submitted the request', 'type' => 'varchar', 'length' => '255', - 'not null' => TRUE, + 'not null' => FALSE, ), 'patron_lastname' => array( 'description' => 'Lastname of the user that submitted the request', @@ -133,6 +133,12 @@ function upei_roblib_ill_schema() { 'length' => '30', 'not null' => TRUE, ), + 'doi' => array( + 'description' => 'The DOI', + 'type' => 'varchar', + 'length' => '255', + 'not null' => FALSE, + ), 'relais_request_id' => array( 'description' => 'The request id stored in the Relais datbabase', 'type' => 'varchar', diff --git a/upei_roblib_ill.module b/upei_roblib_ill.module index d44a8f0..cd4946f 100644 --- a/upei_roblib_ill.module +++ b/upei_roblib_ill.module @@ -36,6 +36,13 @@ function upei_roblib_ill_menu() { 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) { module_load_include('inc', 'upei_roblib_ill', 'includes/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', ), ); + $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( 'title' => t('The Relais request id'), 'help' => t('The Relais request id.'),