Browse Source

relais requests work and result is logged to a database table and table is exposed through hook_views_data

9.x-1.0
ppound 3 years ago
parent
commit
c9304cf331
  1. 3
      includes/db.inc
  2. 14
      includes/relais.inc
  3. 180
      upei_roblib_ill.module

3
includes/db.inc

@ -16,8 +16,9 @@
function upei_roblib_ill_log_request($request, $response) { function upei_roblib_ill_log_request($request, $response) {
$time_submitted = isset($request['RequestInfo']['DateSubmitted']) ? $request['RequestInfo']['DateSubmitted'] : ''; $time_submitted = isset($request['RequestInfo']['DateSubmitted']) ? $request['RequestInfo']['DateSubmitted'] : '';
$relais_message = isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : $response['Problem']['Message']; $relais_message = isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : $response['Problem']['Message'];
$connection = \Drupal::service('database');
try { try {
db_insert('upei_roblib_ill_request') $connection->insert('upei_roblib_ill_request')
->fields([ ->fields([
'patron_id' => $request['DeliveryAddress']['campus_id'], 'patron_id' => $request['DeliveryAddress']['campus_id'],
'patron_firstname' => $request['DeliveryAddress']['FirstName'], 'patron_firstname' => $request['DeliveryAddress']['FirstName'],

14
includes/relais.inc

@ -29,7 +29,7 @@ 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');
$config = \Drupal::config('upei_roblib_ill.settings'); $config = \Drupal::config('upei_roblib_ill.settings');
$url = $config->get('ill_add_url'); $url = trim($config->get('ill_add_url'));
$relais_arr = upei_roblib_ill_build_relais_arr($form_state); $relais_arr = upei_roblib_ill_build_relais_arr($form_state);
$relais_json = json_encode($relais_arr); $relais_json = json_encode($relais_arr);
$options = [ $options = [
@ -45,21 +45,21 @@ function upei_roblib_ill_add_request($form_state, $aid) {
//$result = drupal_http_request($url . '?aid=' . $aid, $options); //$result = drupal_http_request($url . '?aid=' . $aid, $options);
try { try {
$response = \Drupal::httpClient()->post($url . '?aid=' . $aid, $options); $response = \Drupal::httpClient()->post($url . '?aid=' . $aid, $options);
$data = (string) $response->getBody(); //$response_data = (string) $response->getBody();
} }
catch (Exception $e) { catch (Exception $e) {
return ['ConfirmMessage' => 'Error Communicating with Relais, ' . $e->getMessage()]; return ['ConfirmMessage' => 'Error Communicating with Relais, ' . $e->getMessage()];
} }
$response_arr = json_decode($response->getBody(),TRUE); $response_arr = json_decode($response->getBody(),TRUE);
$status_code = $response->getStatusCode(); // for testing $response_arr = array('RequestNumber' => '1234', 'ConfirmMessage' => 'Your request has been submitted');
//$status_code = $response->getStatusCode();
module_load_include('inc', 'upei_roblib_ill', 'includes/db'); module_load_include('inc', 'upei_roblib_ill', 'includes/db');
if (!isset($response_date)) { if (!isset($response_arr)) {
return ['ConfirmMessage' => 'Error Communicating with Relais, no data returned.']; return ['ConfirmMessage' => 'Error Communicating with Relais, no data returned.'];
} }
$response_json = $result->data;
//$response_arr = json_decode($response_json, TRUE);
$response_arr['ConfirmMessage'] = isset($response_arr['Problem']['ErrorMessage']) ? $response_arr['Problem']['ErrorMessage'] : $response_arr['ConfirmMessage']; $response_arr['ConfirmMessage'] = isset($response_arr['Problem']['ErrorMessage']) ? $response_arr['Problem']['ErrorMessage'] : $response_arr['ConfirmMessage'];
//upei_roblib_ill_log_request($relais_arr, $response_arr); upei_roblib_ill_log_request($relais_arr, $response_arr);
return $response_arr; return $response_arr;
} }

180
upei_roblib_ill.module

@ -40,17 +40,17 @@ function upei_roblib_ill_views_data() {
'title' => t('Patron or Campus ID'), 'title' => t('Patron or Campus ID'),
'help' => t('Patron or Campus ID.'), 'help' => t('Patron or Campus ID.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'handler' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
@ -58,14 +58,14 @@ function upei_roblib_ill_views_data() {
'title' => t('Unique ID for an ILL request'), 'title' => t('Unique ID for an ILL request'),
'help' => t('Unique ID for an ILL request.'), 'help' => t('Unique ID for an ILL request.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field_numeric', 'id' => 'numeric',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_numeric', 'id' => 'numeric',
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
]; ];
@ -73,34 +73,34 @@ function upei_roblib_ill_views_data() {
'title' => t('Patron Email Address'), 'title' => t('Patron Email Address'),
'help' => t('Patron Email Address.'), 'help' => t('Patron Email Address.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['patron_lastname'] = [ $data['upei_roblib_ill_request']['patron_lastname'] = [
'title' => t('Patron Lastname'), 'title' => t('Patron Lastname'),
'help' => t('Patron Lastname.'), 'help' => t('Patron Lastname.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
@ -108,306 +108,306 @@ function upei_roblib_ill_views_data() {
'title' => t('Patron Firstame'), 'title' => t('Patron Firstame'),
'help' => t('Patron Firstname.'), 'help' => t('Patron Firstname.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['patron_department'] = [ $data['upei_roblib_ill_request']['patron_department'] = [
'title' => t('Patron Department'), 'title' => t('Patron Department'),
'help' => t('Patron Department.'), 'help' => t('Patron Department.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['patron_type'] = [ $data['upei_roblib_ill_request']['patron_type'] = [
'title' => t('Patron Type'), 'title' => t('Patron Type'),
'help' => t('Patron Type.'), 'help' => t('Patron Type.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['author'] = [ $data['upei_roblib_ill_request']['author'] = [
'title' => t('Authors name'), 'title' => t('Authors name'),
'help' => t('Authors Fullname.'), 'help' => t('Authors Fullname.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['title'] = [ $data['upei_roblib_ill_request']['title'] = [
'title' => t('Book or Journal Title'), 'title' => t('Book or Journal Title'),
'help' => t('Book or Patron Title.'), 'help' => t('Book or Patron Title.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['atitle'] = [ $data['upei_roblib_ill_request']['atitle'] = [
'title' => t('Article or Chapter Title'), 'title' => t('Article or Chapter Title'),
'help' => t('Article or Chapter Title.'), 'help' => t('Article or Chapter Title.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['issn'] = [ $data['upei_roblib_ill_request']['issn'] = [
'title' => t('ISSN'), 'title' => t('ISSN'),
'help' => t('ISSN.'), 'help' => t('ISSN.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['isbn'] = [ $data['upei_roblib_ill_request']['isbn'] = [
'title' => t('ISBN'), 'title' => t('ISBN'),
'help' => t('ISBN.'), 'help' => t('ISBN.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['article_author'] = [ $data['upei_roblib_ill_request']['article_author'] = [
'title' => t('Article or Chapter author'), 'title' => t('Article or Chapter author'),
'help' => t('Article or Chapter author.'), 'help' => t('Article or Chapter author.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['citation_date'] = [ $data['upei_roblib_ill_request']['citation_date'] = [
'title' => t('The date of the article'), 'title' => t('The date of the article'),
'help' => t('Article Date.'), 'help' => t('Article Date.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['pages_requested'] = [ $data['upei_roblib_ill_request']['pages_requested'] = [
'title' => t('The pages requested'), 'title' => t('The pages requested'),
'help' => t('The pages requested.'), 'help' => t('The pages requested.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['volume'] = [ $data['upei_roblib_ill_request']['volume'] = [
'title' => t('Volume'), 'title' => t('Volume'),
'help' => t('Volume.'), 'help' => t('Volume.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['issue'] = [ $data['upei_roblib_ill_request']['issue'] = [
'title' => t('Issue'), 'title' => t('Issue'),
'help' => t('Issue.'), 'help' => t('Issue.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['genre'] = [ $data['upei_roblib_ill_request']['genre'] = [
'title' => t('Genre'), 'title' => t('Genre'),
'help' => t('The type of item requested.'), 'help' => t('The type of item requested.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['doi'] = [ $data['upei_roblib_ill_request']['doi'] = [
'title' => t('DOI'), 'title' => t('DOI'),
'help' => t('DOI.'), 'help' => t('DOI.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'vstring',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['relais_request_id'] = [ $data['upei_roblib_ill_request']['relais_request_id'] = [
'title' => t('The Relais request id'), 'title' => t('The Relais request id'),
'help' => t('The Relais request id.'), 'help' => t('The Relais request id.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['relais_message'] = [ $data['upei_roblib_ill_request']['relais_message'] = [
'title' => t('The reason a request failed.'), 'title' => t('The reason a request failed.'),
'help' => t('The reason a request failed.'), 'help' => t('The reason a request failed.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
$data['upei_roblib_ill_request']['notes'] = [ $data['upei_roblib_ill_request']['notes'] = [
'title' => t('The notes related to this request'), 'title' => t('The notes related to this request'),
'help' => t('The notes related to this request.'), 'help' => t('The notes related to this request.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field', 'id' => 'standard',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort', 'id' => 'standard',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_string', 'id' => 'string',
], ],
'argument' => [ 'argument' => [
'handler' => 'views_handler_argument_string', 'id' => 'string',
], ],
]; ];
@ -415,14 +415,14 @@ function upei_roblib_ill_views_data() {
'title' => t('The Date and Time a request was submitted'), 'title' => t('The Date and Time a request was submitted'),
'help' => t('The Date and Time a request was submitted.'), 'help' => t('The Date and Time a request was submitted.'),
'field' => [ 'field' => [
'handler' => 'views_handler_field_date', 'id' => 'date',
'click sortable' => TRUE, 'click sortable' => TRUE,
], ],
'sort' => [ 'sort' => [
'handler' => 'views_handler_sort_date', 'id' => 'date',
], ],
'filter' => [ 'filter' => [
'handler' => 'views_handler_filter_date', 'id' => 'date',
], ],
]; ];

Loading…
Cancel
Save