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) {
$time_submitted = isset($request['RequestInfo']['DateSubmitted']) ? $request['RequestInfo']['DateSubmitted'] : '';
$relais_message = isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : $response['Problem']['Message'];
$connection = \Drupal::service('database');
try {
db_insert('upei_roblib_ill_request')
$connection->insert('upei_roblib_ill_request')
->fields([
'patron_id' => $request['DeliveryAddress']['campus_id'],
'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/utilities');
$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_json = json_encode($relais_arr);
$options = [
@ -45,21 +45,21 @@ function upei_roblib_ill_add_request($form_state, $aid) {
//$result = drupal_http_request($url . '?aid=' . $aid, $options);
try {
$response = \Drupal::httpClient()->post($url . '?aid=' . $aid, $options);
$data = (string) $response->getBody();
//$response_data = (string) $response->getBody();
}
catch (Exception $e) {
return ['ConfirmMessage' => 'Error Communicating with Relais, ' . $e->getMessage()];
}
$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');
if (!isset($response_date)) {
if (!isset($response_arr)) {
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'];
//upei_roblib_ill_log_request($relais_arr, $response_arr);
upei_roblib_ill_log_request($relais_arr, $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'),
'help' => t('Patron or Campus ID.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'handler' => 'string',
],
'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'),
'help' => t('Unique ID for an ILL request.'),
'field' => [
'handler' => 'views_handler_field_numeric',
'id' => 'numeric',
'click sortable' => TRUE,
],
'filter' => [
'handler' => 'views_handler_filter_numeric',
'id' => 'numeric',
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
];
@ -73,34 +73,34 @@ function upei_roblib_ill_views_data() {
'title' => t('Patron Email Address'),
'help' => t('Patron Email Address.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['patron_lastname'] = [
'title' => t('Patron Lastname'),
'help' => t('Patron Lastname.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
@ -108,306 +108,306 @@ function upei_roblib_ill_views_data() {
'title' => t('Patron Firstame'),
'help' => t('Patron Firstname.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['patron_department'] = [
'title' => t('Patron Department'),
'help' => t('Patron Department.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['patron_type'] = [
'title' => t('Patron Type'),
'help' => t('Patron Type.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['author'] = [
'title' => t('Authors name'),
'help' => t('Authors Fullname.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['title'] = [
'title' => t('Book or Journal Title'),
'help' => t('Book or Patron Title.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['atitle'] = [
'title' => t('Article or Chapter Title'),
'help' => t('Article or Chapter Title.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['issn'] = [
'title' => t('ISSN'),
'help' => t('ISSN.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['isbn'] = [
'title' => t('ISBN'),
'help' => t('ISBN.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['article_author'] = [
'title' => t('Article or Chapter author'),
'help' => t('Article or Chapter author.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['citation_date'] = [
'title' => t('The date of the article'),
'help' => t('Article Date.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['pages_requested'] = [
'title' => t('The pages requested'),
'help' => t('The pages requested.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['volume'] = [
'title' => t('Volume'),
'help' => t('Volume.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['issue'] = [
'title' => t('Issue'),
'help' => t('Issue.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['genre'] = [
'title' => t('Genre'),
'help' => t('The type of item requested.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['doi'] = [
'title' => t('DOI'),
'help' => t('DOI.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'vstring',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['relais_request_id'] = [
'title' => t('The Relais request id'),
'help' => t('The Relais request id.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['relais_message'] = [
'title' => t('The reason a request failed.'),
'help' => t('The reason a request failed.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
'id' => 'string',
],
];
$data['upei_roblib_ill_request']['notes'] = [
'title' => t('The notes related to this request'),
'help' => t('The notes related to this request.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'standard',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort',
'id' => 'standard',
],
'filter' => [
'handler' => 'views_handler_filter_string',
'id' => 'string',
],
'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'),
'help' => t('The Date and Time a request was submitted.'),
'field' => [
'handler' => 'views_handler_field_date',
'id' => 'date',
'click sortable' => TRUE,
],
'sort' => [
'handler' => 'views_handler_sort_date',
'id' => 'date',
],
'filter' => [
'handler' => 'views_handler_filter_date',
'id' => 'date',
],
];

Loading…
Cancel
Save