Browse Source

start of logging and view of log data

9.x-1.0
Paul Pound 8 years ago
parent
commit
3177cf089e
  1. 35
      includes/db.inc
  2. 10
      includes/doi.inc
  3. 6
      includes/relais.inc
  4. 145
      upei_roblib_ill.install
  5. 405
      upei_roblib_ill.module

35
includes/db.inc

@ -0,0 +1,35 @@
<?php
/**
* @file
* functions for database access.
*/
function upei_roblib_ill_log_request($request, $respose) {
try {
db_insert('upei_roblib_ill_request')
->fields(array(
'patron_id' => $request['DeliveryAddress']['campus_id'],
'patron_firstname' => $request['DeliveryAddress']['FirstName'],
'patron_lastname' => $request['DeliveryAddress']['Surname'],
'patron_type' => $request['DeliveryAddress']['patron_type'],
'patron_department' => $request['DeliveryAddress']['Department'],
'patron_email' => $request['DeliveryAddress']['DeliveryAddress'],
'notes' => $request['DeliveryAddress']['notes'],
'genre' => $request['BibliographicInfo']['Genre'],
'author' => $request['BibliographicInfo']['Author'],
'citation_date' => $request['BibliographicInfo']['Date'],
'title' => $request['DeliveryAddress']['Title'],
'atitle' => $request['DeliveryAddress']['ArticleTitle'],
'issn' => $request['DeliveryAddress']['issn'],
'isbn' => $request['DeliveryAddress']['isbn'],
'article_author' => $request['DeliveryAddress']['ArtigleAuthor'],
'volume' => $request['DeliveryAddress']['Volume'],
'issue' => $request['DeliveryAddress']['Issue'],
'pages_requested' => $request['DeliveryAddress']['PagesRequested'],
'time_submitted' => strtotime($request['RequestInfo']['DateSubmitted']),
))->execute();
} catch(Exception $e) {
watchdog_exception('upei_roblib_ill', $e, 'Error logging ILL request.', array(), WATCHDOG_ERROR);
}
}

10
includes/doi.inc

@ -34,6 +34,16 @@ function upei_roblib_ill_doi_get_data($form, $doi) {
} }
} }
/**
* Parse the response from Crossref and populate the request form
* @param DomDocument $crossref_xml
* The crossref xml
* @param array $form
* Drupal form
* @return mixed
* A Drupal form
*/
function upei_roblib_ill_populate_form_doi($crossref_xml, $form) { function upei_roblib_ill_populate_form_doi($crossref_xml, $form) {
$full_title = $crossref_xml->getElementsbyTagName('full_title') $full_title = $crossref_xml->getElementsbyTagName('full_title')
->item(0)->nodeValue; ->item(0)->nodeValue;

6
includes/relais.inc

@ -28,10 +28,14 @@ function upei_roblib_ill_add_request($form_state, $aid) {
'timeout' => 15, 'timeout' => 15,
'headers' => array('Content-Type' => 'application/json'), 'headers' => array('Content-Type' => 'application/json'),
); );
$result = drupal_http_request($url . '?aid=' . $aid, $options); $result = null;// = drupal_http_request($url . '?aid=' . $aid, $options);
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
upei_roblib_ill_log_request($relais_arr, NULL);
if ($result->code == '200') { if ($result->code == '200') {
$response_json = $result->data; $response_json = $result->data;
$response_arr = json_decode($response_json); $response_arr = json_decode($response_json);
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
upei_roblib_ill_log_request($relais_arr, $response_arr);
//TODO remove or improve the line below after testing //TODO remove or improve the line below after testing
drupal_set_message('submitted request to relais' . $response_json); drupal_set_message('submitted request to relais' . $response_json);
} }

145
upei_roblib_ill.install

@ -17,3 +17,148 @@ function upei_roblib_ill_uninstall() {
); );
array_walk($variables, 'variable_del'); array_walk($variables, 'variable_del');
} }
/**
* Implements hook_schema().
*/
function upei_roblib_ill_schema() {
$schema['upei_roblib_ill_request'] = array(
'description' => 'Log table for ILL requests',
'fields' => array(
'id' => array(
'description' => 'primary key',
'type' => 'serial',
'size' => 'big',
'not null' => TRUE,
),
'patron_id' => array(
'description' => 'The id of the user that submitted the request',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'patron_email' => array(
'description' => 'The email address of the user that submitted the request',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'patron_lastname' => array(
'description' => 'Lastname of the user that submitted the request',
'type' => 'varchar',
'length' => '60',
'not null' => TRUE,
),
'patron_firstname' => array(
'description' => 'Firstname of the user that submitted the request',
'type' => 'varchar',
'length' => '60',
'not null' => TRUE,
),
'patron_department' => array(
'description' => 'The department the user that submitted the request belongs',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
),
'patron_type' => array(
'description' => 'The type of patron ',
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
),
'author' => array(
'description' => 'authors name',
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
),
'title' => array(
'description' => 'book or journal title',
'type' => 'varchar',
'length' => '512',
'not null' => FALSE,
),
'atitle' => array(
'description' => 'article or chapter title',
'type' => 'varchar',
'length' => '512',
'not null' => FALSE,
),
'issn' => array(
'description' => 'Article issn',
'type' => 'varchar',
'length' => '18',
'not null' => FALSE,
),
'isbn' => array(
'description' => 'book isbn',
'type' => 'varchar',
'length' => '8',
'not null' => FALSE,
),
'article_author' => array(
'description' => 'Article author',
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
),
'citation_date' => array(
'description' => 'Date and time of the request',
'type' => 'varchar',
'length' => '30',
'not null' => TRUE,
),
'pages_requested' => array(
'description' => 'pages requested',
'type' => 'varchar',
'length' => '30',
'not null' => FALSE,
),
'volume' => array(
'description' => 'Volume',
'type' => 'varchar',
'length' => '30',
'not null' => FALSE,
),
'issue' => array(
'description' => 'Issue',
'type' => 'varchar',
'length' => '50',
'not null' => FALSE,
),
'genre' => array(
'description' => 'type of material requested (article, book, book chapter)',
'type' => 'varchar',
'length' => '30',
'not null' => TRUE,
),
'relais_request_id' => array(
'description' => 'The request id stored in the Relais datbabase',
'type' => 'varchar',
'length' => '30',
'not null' => FALSE,
),
'relais_failure_message' => array(
'description' => 'If the ILL request failed we will store a reason.',
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'time_submitted' => array(
'description' => 'The time the request was submitted',
'type' => 'int',
'not null' => FALSE,
),
'notes' => array(
'description' => 'Notes',
'type' => 'varchar',
'length' => '512',
'not null' => FALSE,
),
),
'primary key' => array('id'),
);
return $schema;
}

405
upei_roblib_ill.module

@ -34,5 +34,410 @@ function upei_roblib_ill_doi_callback($form, &$form_state) {
return $form; return $form;
} }
/**
* Implements hook_views_api().
*/
function upei_roblib_ill_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'upei_roblib_ill') . '/views',
);
}
/**
* Implements hook_views_data().
*/
function upei_roblib_ill_views_data() {
$data['upei_roblib_ill_request']['table']['group'] = t('UPEI Roblib ILL');
$data['upei_roblib_ill_request']['table']['base'] = array(
'field' => 'id', // This is the identifier field for the view.
'title' => t('UPEI Roblib ILL Request'),
'help' => t('Table for logging ILL Request'),
'weight' => -10,
);
$data['upei_roblib_ill_request']['patron_id'] = array(
'title' => t('Patron or Campus ID'),
'help' => t('Patron or Campus ID.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['id'] = array(
'title' => t('Unique ID for an ILL request'),
'help' => t('Unique ID for an ILL request.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['upei_roblib_ill_request']['patron_email'] = array(
'title' => t('Patron Email Address'),
'help' => t('Patron Email Address.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['patron_lastname'] = array(
'title' => t('Patron Lastname'),
'help' => t('Patron Lastname.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['patron_firstname'] = array(
'title' => t('Patron Firstame'),
'help' => t('Patron Firstname.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['patron_department'] = array(
'title' => t('Patron Department'),
'help' => t('Patron Department.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['patron_type'] = array(
'title' => t('Patron Type'),
'help' => t('Patron Type.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['author'] = array(
'title' => t('Authors name'),
'help' => t('Authors Fullname.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['title'] = array(
'title' => t('Book or Journal Title'),
'help' => t('Book or Patron Title.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['atitle'] = array(
'title' => t('Article or Chapter Title'),
'help' => t('Article or Chapter Title.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['issn'] = array(
'title' => t('ISSN'),
'help' => t('ISSN.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['isbn'] = array(
'title' => t('ISBN'),
'help' => t('ISBN.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['article_author'] = array(
'title' => t('Article or Chapter author'),
'help' => t('Article or Chapter author.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['citation_date'] = array(
'title' => t('The date of the article'),
'help' => t('Article Date.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['pages_requested'] = array(
'title' => t('The pages requested'),
'help' => t('The pages requested.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['volume'] = array(
'title' => t('Volume'),
'help' => t('Volume.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['issue'] = array(
'title' => t('Issue'),
'help' => t('Issue.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['genre'] = array(
'title' => t('Article or Chapter author'),
'help' => t('Article or Chapter author.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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_failure_message'] = array(
'title' => t('The reason a request failed. '),
'help' => t('The reason a request failed.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'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']['notes'] = array(
'title' => t('The notes related to this request'),
'help' => t('The notes related to this request.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE, // This is use by the table display plugin.
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// Example timestamp field.
$data['upei_roblib_ill_request']['time_submitted'] = array(
'title' => t('The Date and Time a request was submitted'),
'help' => t('The Date and Time a request was submitted.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}

Loading…
Cancel
Save