Browse Source

coder fixes after updating coder and intellij

9.x-1.0
Paul Pound 8 years ago
parent
commit
86e46f4dd9
  1. 30
      includes/admin.form.inc
  2. 7
      includes/db.inc
  3. 30
      includes/doi.inc
  4. 271
      includes/form.inc
  5. 39
      includes/relais.inc
  6. 31
      includes/utilities.inc
  7. 106
      upei_roblib_ill.install
  8. 485
      upei_roblib_ill.module

30
includes/admin.form.inc

@ -6,8 +6,8 @@
function upei_roblib_ill_admin_form($form, &$form_state) {
$form = array();
$form['upei_roblib_ill_add_url'] = array(
$form = [];
$form['upei_roblib_ill_add_url'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
@ -15,8 +15,8 @@ function upei_roblib_ill_admin_form($form, &$form_state) {
'#description' => t('The URL for the Relais ILL server AddRequest service, the default is
https://caul-cbua.relais-host.com/portal-service/request/add'),
'#default_value' => variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add'),
);
$form['upei_roblib_ill_auth_url'] = array(
];
$form['upei_roblib_ill_auth_url'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
@ -24,48 +24,48 @@ function upei_roblib_ill_admin_form($form, &$form_state) {
'#description' => t('The URL for the Relais ILL server Auth service (retrieve the aid), the default is
https://caul-cbua.relais-host.com/portal-service/user/authentication'),
'#default_value' => variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication'),
);
$form['upei_roblib_ill_library_symbol'] = array(
];
$form['upei_roblib_ill_library_symbol'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Your Relais Library Symbol'),
'#description' => t('Your Relais Library Symbol'),
'#default_value' => variable_get('upei_roblib_ill_library_symbol'),
);
];
$form['upei_roblib_ill_relais_key'] = array(
$form['upei_roblib_ill_relais_key'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('The Relais API key'),
'#description' => t('The API key used to communicate with the Relais API, Contact Relais International to get your key'),
'#default_value' => variable_get('upei_roblib_ill_relais_key'),
);
$form['upei_roblib_ill_doi_openurl_pid'] = array(
];
$form['upei_roblib_ill_doi_openurl_pid'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('OpenURL PID'),
'#description' => t('An identifier to call yourself, for the OpenURL endpoint. To use this service you first need to register for an account here: http://www.crossref.org/requestaccount/'),
'#default_value' => variable_get('upei_roblib_ill_doi_openurl_pid'),
);
$form['upei_roblib_ill_contact_email'] = array(
];
$form['upei_roblib_ill_contact_email'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Contact Email'),
'#description' => t('The email address we want to show after a user has submitted an ILL request'),
'#default_value' => variable_get('upei_roblib_ill_contact_email', 'ill@upei.ca'),
);
$form['upei_roblib_ill_contact_phone'] = array(
];
$form['upei_roblib_ill_contact_phone'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Contact Phone Number'),
'#description' => t('The phone number we want to show to the user after a user has submitted an ILL request'),
'#default_value' => variable_get('upei_roblib_ill_contact_phone', '902-566-0445'),
);
];
return system_settings_form($form);

7
includes/db.inc

@ -7,6 +7,7 @@
/**
* Log an ILL request
*
* @param array $request
* The request sent to Relais as an array (before it is encoded as JSON)
* @param array $response
@ -17,7 +18,7 @@ function upei_roblib_ill_log_request($request, $response) {
$relais_message = isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : $response['Problem']['Message'];
try {
db_insert('upei_roblib_ill_request')
->fields(array(
->fields([
'patron_id' => $request['DeliveryAddress']['campus_id'],
'patron_firstname' => $request['DeliveryAddress']['FirstName'],
'patron_lastname' => $request['DeliveryAddress']['Surname'],
@ -40,8 +41,8 @@ function upei_roblib_ill_log_request($request, $response) {
'time_submitted' => strtotime($time_submitted),
'relais_request_id' => isset($response['RequestNumber']) ? $response['RequestNumber'] : '-1',
'relais_message' => $relais_message,
))->execute();
])->execute();
} catch (Exception $e) {
watchdog_exception('upei_roblib_ill', $e, 'Error logging ILL request.', array(), WATCHDOG_ERROR);
watchdog_exception('upei_roblib_ill', $e, 'Error logging ILL request.', [], WATCHDOG_ERROR);
}
}

30
includes/doi.inc

@ -7,11 +7,14 @@
*/
/**
* Gets the XML as crossref associated with the supplied DOI. Updates the drupal form with the data.
* Gets the XML as crossref associated with the supplied DOI. Updates the
* drupal form with the data.
*
* @param array $form
* The Drupal form
* @param string $doi
* The DOI
*
* @return array
* A Drupal form with updated values.
*/
@ -39,36 +42,43 @@ function upei_roblib_ill_doi_get_data($form, $doi) {
}
}
else {
drupal_set_message(t('Error retrieve data using DOI of @doi', array('@doi' => $doi)), 'error');
drupal_set_message(t('Error retrieve data using DOI of @doi', ['@doi' => $doi]), 'error');
return $form;
}
}
/**
* A convenience function for retrieving individual nodes from the Crossref XML without throwing notices.
* A convenience function for retrieving individual nodes from the Crossref XML
* without throwing notices.
*
* @param DomDocument $crossref_xml
* The Crossref XML
* @param string $node_name
* The node we want a value for, we are assuming the xml only has one node with the given name.
* The node we want a value for, we are assuming the xml only has one node
* with the given name.
* @param int $index
* If there are more than one element we can ask for the value of each element
* If there are more than one element we can ask for the value of each
* element
*
* @return string
* Returns the value of the element
*/
function upei_roblib_ill_get_xml_node($crossref_xml, $node_name, $index = 0) {
// TODO rewrite this function to use full xpath
return empty($crossref_xml->getElementsbyTagName($node_name)->item($index)) ? '' :
return empty($crossref_xml->getElementsbyTagName($node_name)
->item($index)) ? '' :
$crossref_xml->getElementsbyTagName($node_name)->item($index)->nodeValue;
}
/**
* Parse the response from Crossref and populate the request form
*
* @param DomDocument $crossref_xml
* The crossref xml
* @param array $form
* Drupal form
*
* @return mixed
* An updated Drupal form
*/
@ -151,14 +161,14 @@ function upei_roblib_ill_doi_load($doi, $parse = TRUE) {
$id = $parse ? upei_roblib_ill_doi_name_from_url($doi) : $doi;
$openurl = variable_get('upei_roblib_ill_doi_openurl', 'http://www.crossref.org/openurl');
$openurl_pid = variable_get('upei_roblib_ill_doi_openurl_pid', 'user@example.com');
$url = url($openurl, array(
'query' => array(
$url = url($openurl, [
'query' => [
'noredirect' => 'true',
'pid' => $openurl_pid,
'format' => 'unixref',
'id' => ((strpos($id, 'doi:') === 0) ? $id : 'doi:' . $id),
),
));
],
]);
return drupal_http_request($url);
}

271
includes/form.inc

@ -88,62 +88,65 @@ function upei_roblib_ill_form_submit($form, &$form_state) {
$response = upei_roblib_ill_add_request($form_state, $form_state['storage']['aid']);
$error = isset($response['RequestNumber']) ? 'FALSE' : 'TRUE';
$form_state['redirect'] = array(
$form_state['redirect'] = [
'/upei/roblib/ill/finished',
array(
'query' => array(
[
'query' => [
'message' => $response['ConfirmMessage'],
'email' => $form_state['values']['DeliveryAddress'],
'error' => $error,
),
),
);
],
],
];
}
}
/**
* After submitting an ILL request patrons will be redirected to the content returned from this function.
* After submitting an ILL request patrons will be redirected to the content
* returned from this function.
*
* @return string
* a string of HTML to display including the results of the ILL request and some boilerplate text.
* a string of HTML to display including the results of the ILL request and
* some boilerplate text.
*/
function upei_roblib_ill_form_redirect() {
$contact_email = variable_get('upei_roblib_ill_contact_email', 'ill@upei.ca');
$contact_phone_number = variable_get('upei_roblib_ill_contact_phone', '902-566-0445');
$librarian_link = l(t('subject-specific'), 'http://library.upei.ca/librarians', array('html' => TRUE));
$librarian_link = l(t('subject-specific'), 'http://library.upei.ca/librarians', ['html' => TRUE]);
$help_message = t("We can help! Please contact your !librarian_link librarian if you'd like help finding more resources relating to your topic.",
array('!librarian_link' => $librarian_link));
['!librarian_link' => $librarian_link]);
$standard_message = t("To contact the department about this request, you can send a message to @email or
call @phone.", array('@phone' => $contact_phone_number, '@email' => $contact_email));
call @phone.", ['@phone' => $contact_phone_number, '@email' => $contact_email]);
if (isset($_GET['error']) && $_GET['error'] === 'FALSE') {
$standard_message = t("A message including the Request ID has been sent to @email. ", array(
$standard_message = t("A message including the Request ID has been sent to @email.", [
'@email' => $_GET['email'],
)) . $standard_message;
]) . $standard_message;
}
$output = array(
$output = [
'#prefix' => '<div upei-roblib-ill-content>',
'#suffix' => '</div>',
'dynamic_message' => array(
'dynamic_message' => [
'#type' => 'markup',
'#markup' => $_GET['message'],
'#prefix' => '<div class="upei-roblib-ill-message">',
'#suffix' => '</div>',
),
'standard_message' => array(
],
'standard_message' => [
'#type' => 'markup',
'#markup' => $standard_message,
'#prefix' => '<div class="upei-roblib-ill-email">',
'#suffix' => '</div>',
),
'help_message' => array(
],
'help_message' => [
'#type' => 'markup',
'#markup' => $help_message,
'#allowed_tags' => ['a', 'source'],
'#prefix' => '<div class="upei-roblib-ill-help">',
'#suffix' => '</div>',
),
);
],
];
return drupal_render($output);
}
@ -165,25 +168,25 @@ function upei_roblib_ill_auth_form($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$form['#prefix'] = upei_roblib_format_biblio_info($form_state);
$form['FirstName'] = array(
$form['FirstName'] = [
'#type' => 'textfield',
'#title' => t('Your First Name'),
'#size' => 50,
'#required' => TRUE,
);
$form['Surname'] = array(
];
$form['Surname'] = [
'#type' => 'textfield',
'#title' => t('Your Last Name'),
'#size' => 50,
'#required' => TRUE,
);
$form['campus_id'] = array(
];
$form['campus_id'] = [
'#type' => 'textfield',
'#title' => t('Your Campus ID'),
'#size' => 50,
'#required' => TRUE,
);
$patron_types = array(
];
$patron_types = [
'None' => t('None'),
'UPEI Faculty/Staff' => t('UPEI Faculty/Staff'),
'UPEI Graduate Student' => t('UPEI Graduate Student'),
@ -192,8 +195,8 @@ function upei_roblib_ill_auth_form($form, &$form_state) {
'UPEI Alumni Premiere member' => t('UPEI Alumni Premiere member'),
'UPEI Alumni member' => t('UPEI Alumni member'),
'Public Borrower' => t('Public Borrower'),
);
$departments = array(
];
$departments = [
'Applied Human Sciences' => t('Applied Human Sciences'),
'AVC - Biomedical Sciences' => t('AVC - Biomedical Sciences'),
'AVC - Companion Animals' => t('AVC - Companion Animals'),
@ -227,56 +230,56 @@ function upei_roblib_ill_auth_form($form, &$form_state) {
'Religious Studies' => t('Religious Studies'),
'Sociology/Anthropology' => t('Sociology/Anthropology'),
'Other' => t('Other (Please add to the Notes field)'),
);
$form['patron_type'] = array(
];
$form['patron_type'] = [
'#type' => 'select',
'#title' => t('Your Patron Type'),
'#options' => $patron_types,
'#required' => TRUE,
);
$form['Department'] = array(
];
$form['Department'] = [
'#type' => 'select',
'#title' => t('Your Department'),
'#options' => $departments,
'#required' => TRUE,
);
$form['DeliveryAddress'] = array(
];
$form['DeliveryAddress'] = [
'#type' => 'textfield',
'#title' => t('Your Email'),
'#size' => 50,
'#required' => TRUE,
);
$form['InstitutionName'] = array(
];
$form['InstitutionName'] = [
'#type' => 'hidden',
'#title' => t('Name of Institution'),
'#size' => 50,
'#default_value' => 'University of Prince Edward Island',
'#required' => TRUE,
);
$form['LibraryName'] = array(
];
$form['LibraryName'] = [
'#type' => 'hidden',
'#title' => t('Name of Library'),
'#size' => 50,
'#default_value' => 'Robertson Library',
'#required' => TRUE,
);
$form['notes'] = array(
];
$form['notes'] = [
'#type' => 'textarea',
'#title' => t('Notes'),
'#size' => 50,
'#required' => FALSE,
);
$form['certify'] = array(
];
$form['certify'] = [
'#title' => t('I certify'),
'#type' => 'checkbox',
'#description' => 'I hereby certify that this item is being sought for a fair dealing purpose and any copying will be in accordance with the Copyright Act. ',
'#size' => 50,
'#required' => TRUE,
);
$form['submit'] = array(
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
);
];
return $form;
@ -299,47 +302,47 @@ function upei_roblib_ill_request_form($form, &$form_state) {
$form['#prefix'] = '<div id="upei-roblib-ill-request-form">';
$form['#suffix'] = '</div>';
$genre = empty(upei_roblib_ill_get_request_variable('genre')) ? 'article' : upei_roblib_ill_get_request_variable('genre');
$form['Genre'] = array(
$form['Genre'] = [
'#type' => 'select',
'#title' => t('Genre'),
'#default_value' => $genre,
'#options' => array(
'#options' => [
'article' => t('Journal Article'),
'book' => t('Book'),
'chapter' => t('Book Chapter'),
),
],
'#required' => TRUE,
);
$form['doi'] = array(
];
$form['doi'] = [
'#type' => 'textfield',
'#title' => t('DOI'),
'#default_value' => upei_roblib_ill_get_doi_from_request(),
'#description' => 'DOI, if you provide a DOI we will attempt to lookup the record for you',
'#size' => 50,
'#states' => array(
'visible' => array(
':input[name="Genre"]' => array('value' => 'article'),
),
),
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
'#required' => FALSE,
);
$form['doi_button'] = array(
];
$form['doi_button'] = [
'#type' => 'submit',
'#value' => 'lookup DOI',
'#ajax' => array(
'#ajax' => [
'callback' => 'upei_roblib_ill_doi_callback',
'method' => 'replace',
'wrapper' => 'upei-roblib-ill-request-form',
'effect' => 'fade',
),
'#states' => array(
'visible' => array(
':input[name="Genre"]' => array('value' => 'article'),
),
),
],
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
'#required' => FALSE,
);
$form['Title'] = array(
];
$form['Title'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Source Title'),
@ -347,136 +350,136 @@ function upei_roblib_ill_request_form($form, &$form_state) {
'#description' => 'Journal or Book Title (Required)',
'#size' => 50,
'#required' => FALSE,
);
$form['ArticleTitle'] = array(
];
$form['ArticleTitle'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Title'),
'#default_value' => upei_roblib_ill_get_request_variable('atitle'),
'#description' => 'Article or Chapter Title',
'#size' => 50,
'#states' => array(
'invisible' => array(
':input[name="Genre"]' => array('value' => 'book'),
),
),
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
'#required' => FALSE,
);
];
$form['ISSN'] = array(
$form['ISSN'] = [
'#type' => 'textfield',
'#title' => t('ISSN'),
'#default_value' => upei_roblib_ill_get_request_variable('issn'),
'#size' => 50,
'#states' => array(
'visible' => array(
':input[name="Genre"]' => array('value' => 'article'),
),
),
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
'#required' => FALSE,
);
];
$article_author = ($genre == 'book') ? '' : upei_roblib_ill_get_request_variable('author');
$form['ArticleAuthor'] = array(
$form['ArticleAuthor'] = [
'#type' => 'textfield',
'#title' => t('Author'),
'#default_value' => $article_author,
'#size' => 50,
'#required' => FALSE,
'#description' => 'Article or Chapter Author',
'#states' => array(
'invisible' => array(
':input[name="Genre"]' => array('value' => 'book'),
),
),
);
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
];
$author = ($genre == 'book') ? upei_roblib_ill_get_request_variable('author') : '';
$form['Author'] = array(
$form['Author'] = [
'#type' => 'textfield',
'#title' => t('Book Author'),
'#default_value' => $author,
'#size' => 50,
'#required' => FALSE,
'#states' => array(
'invisible' => array(
':input[name="Genre"]' => array('value' => t('article')),
),
),
);
$form['ISBN'] = array(
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => t('article')],
],
],
];
$form['ISBN'] = [
'#type' => 'textfield',
'#title' => t('ISBN'),
'#default_value' => upei_roblib_ill_get_request_variable('isbn'),
'#size' => 50,
'#states' => array(
'invisible' => array(
':input[name="Genre"]' => array('value' => 'article'),
),
),
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
'#required' => FALSE,
);
$form['SubTitle'] = array(
];
$form['SubTitle'] = [
'#type' => 'hidden',
'#title' => t('Sub Title'),
'#default_value' => upei_roblib_ill_get_request_variable('ubtitle'),
'#size' => 50,
'#required' => FALSE,
);
$form['SeriesTitle'] = array(
];
$form['SeriesTitle'] = [
'#type' => 'hidden',
'#title' => t('Series Title'),
'#default_value' => upei_roblib_ill_get_request_variable('stitle'),
'#size' => 50,
'#required' => FALSE,
);
];
$form['Volume'] = array(
$form['Volume'] = [
'#type' => 'textfield',
'#title' => t('Volume'),
'#default_value' => upei_roblib_ill_get_request_variable('volume'),
'#size' => 50,
'#required' => FALSE,
'#states' => array(
'visible' => array(
':input[name="Genre"]' => array('value' => 'article'),
),
),
);
$form['Issue'] = array(
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
];
$form['Issue'] = [
'#type' => 'textfield',
'#title' => t('Issue'),
'#default_value' => upei_roblib_ill_get_request_variable('issue'),
'#size' => 50,
'#required' => FALSE,
'#states' => array(
'visible' => array(
':input[name="Genre"]' => array('value' => 'article'),
),
),
);
$form['PagesRequested'] = array(
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
];
$form['PagesRequested'] = [
'#type' => 'textfield',
'#title' => t('Pages'),
'#default_value' => upei_roblib_ill_get_request_variable('pages'),
'#description' => 'Pages requested (startpage-endpage)',
'#size' => 50,
'#required' => FALSE,
'#states' => array(
'invisible' => array(
':input[name="Genre"]' => array('value' => 'book'),
),
),
);
$form['Date'] = array(
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
];
$form['Date'] = [
'#type' => 'textfield',
'#title' => t('Date'),
'#default_value' => upei_roblib_ill_get_request_variable('date'),
'#size' => 50,
'#required' => FALSE,
);
$form['next'] = array(
];
$form['next'] = [
'#type' => 'submit',
'#value' => t('Next')
);
'#value' => t('Next'),
];
return $form;
}

39
includes/relais.inc

@ -22,6 +22,7 @@ function upei_roblib_ill_get_pub_type($genre) {
* 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) {
@ -30,21 +31,21 @@ function upei_roblib_ill_add_request($form_state, $aid) {
$url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add');
$relais_arr = upei_roblib_ill_build_relais_arr($form_state);
$relais_json = json_encode($relais_arr);
$options = array(
$options = [
'method' => 'POST',
'data' => $relais_json,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/json'),
);
'headers' => ['Content-Type' => 'application/json'],
];
if (!isset($aid) || is_array($aid)) {
upei_roblib_ill_log_request($relais_arr, $aid);
drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $aid['Problem']['Message'])), 'error');
return array('ConfirmMessage' => t('There was an error processing your request, @msg', array('@msg' => $aid['Problem']['Message'])));
drupal_set_message(t('Error retrieving authentication token, @message', ['@message' => $aid['Problem']['Message']]), 'error');
return ['ConfirmMessage' => t('There was an error processing your request, @msg', ['@msg' => $aid['Problem']['Message']])];
}
$result = drupal_http_request($url . '?aid=' . $aid, $options);
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
if (!isset($result->data)) {
return array('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);
@ -55,13 +56,14 @@ function upei_roblib_ill_add_request($form_state, $aid) {
/**
* @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(
$relais_arr = [
"SupplyingLibrarySymbol" => variable_get('upei_roblib_ill_library_symbol', 'PCU'),
);
];
$pub_type = upei_roblib_ill_get_pub_type($form_state['storage']['upei_roblib_ill_request_form']['Genre']);
$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']);
@ -80,25 +82,29 @@ function upei_roblib_ill_build_relais_arr($form_state) {
/**
* Request an aid from Relais.
*
* @param string $barcode
* A patron_id, campus_id or barcode to identify a user
*
* @return string/array
* Returns a Relais authentication id (token) or an array containing the Relais response error which should include the error message if authentication fails
* Returns a Relais authentication id (token) or an array containing the
* Relais response error which should include the error message if
* authentication fails
*/
function upei_roblib_ill_authenticate($barcode, $surname) {
$url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication');
$json_arr = array();
$json_arr = [];
$json_arr['ApiKey'] = variable_get('upei_roblib_ill_relais_key');
$json_arr['UserGroup'] = 'patron';
$json_arr['LibrarySymbol'] = variable_get('upei_roblib_ill_library_symbol');
$json_arr['PatronId'] = $barcode;
$request_json = json_encode($json_arr);
$options = array(
$options = [
'method' => 'POST',
'data' => $request_json,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/json'),
);
'headers' => ['Content-Type' => 'application/json'],
];
$result = drupal_http_request($url, $options);
if ($result->code != '200') {
$response_data['Problem']['Message'] = $result->error;
@ -124,6 +130,11 @@ function upei_roblib_ill_build_err_msg($msg_from_server) {
return t('Oops. Something went wrong.<br />Check the "Your Last Name" and "Your Campus ID" fields - those two need to match what is on file
. (Your !campus_id appears as the NUMBER near the middle of your campus card). If you do not have a !campus_id, please contact the Robertson Library Service Desk, or,
call !phone. Note: if you are a student taking online courses only, please email !ill_email.<br />@msg_from_server',
array('!campus_id' => $campus_id, '!ill_email' => $ill_email, '!phone' => $phone, '@msg_from_server' => $server_response));
[
'!campus_id' => $campus_id,
'!ill_email' => $ill_email,
'!phone' => $phone,
'@msg_from_server' => $server_response,
]);
}

31
includes/utilities.inc

@ -13,7 +13,8 @@
function upei_roblib_ill_check_arr_item(&$value, $key) {
if (is_array($value)) {
array_walk($value, 'upei_roblib_ill_check_arr_item');
} else {
}
else {
$value = filter_xss($value);
}
}
@ -23,6 +24,7 @@ function upei_roblib_ill_check_arr_item(&$value, $key) {
*
* @param $values
* A drupal form_state['values] array
*
* @return array
* An array where the keys in the array that have empty values are removed and
* drupal specific elements are removed.
@ -30,10 +32,10 @@ function upei_roblib_ill_check_arr_item(&$value, $key) {
function upei_roblib_ill_clean_array($values) {
$arr = array_filter($values);
if (isset($arr['ISSN'])) {
$arr['ISSN'] = array($arr['ISSN']);
$arr['ISSN'] = [$arr['ISSN']];
}
if (isset($arr['ISBN'])) {
$arr['ISBN'] = array($arr['ISBN']);
$arr['ISBN'] = [$arr['ISBN']];
}
// The below checks are due to ebscos habit of sending sending the same info in both atitle and title etc.
if (isset($arr['Genre']) && $arr['Genre'] == 'article' && isset($arr['Author'])) {
@ -66,10 +68,12 @@ function upei_roblib_ill_clean_array($values) {
}
/**
* Allows us to ask for _REQUEST variables that may or may not exist without generating a php warning.
* Also does some formatting for certain variables.
* Allows us to ask for _REQUEST variables that may or may not exist without
* generating a php warning. Also does some formatting for certain variables.
*
* @param string $variable
* The name of the $_REQUEST variable to check
*
* @return string
* The value of the $_REQUEST variable or an empty string.
*/
@ -104,13 +108,15 @@ function upei_roblib_ill_get_doi_from_id() {
/**
* Populates the requestInfo portion of a Relais request
*
* @param array $values
* an array containing a 'Genre' element.
*
* @return array
* The requestInfo portion of a Relais request
*/
function upei_roblib_ill_request_info_array($values, $notes) {
$requestInfo = array();
$requestInfo = [];
$genre = $values['Genre'];
$requestInfo['DateSubmitted'] = date('Y-m-d H:i:s');
$requestInfo['Notes'] = $notes;
@ -128,25 +134,28 @@ function upei_roblib_ill_request_info_array($values, $notes) {
}
/**
* Creates a summary Table based on the biblio information in the form_state array for display
* Creates a summary Table based on the biblio information in the form_state
* array for display
*
* @param $form_state
*
* @return string
*/
function upei_roblib_format_biblio_info($form_state) {
$data = upei_roblib_ill_clean_array($form_state['storage']['upei_roblib_ill_request_form']);
$rows = array();
$rows = [];
foreach ($data as $key => $value) {
if ($key == 'ISSN' || $key == 'ISBN') {
$value = reset($value);
}
array_push($rows, array($key, $value));
array_push($rows, [$key, $value]);
}
$output = array(
$output = [
'#theme' => 'table',
'#rows' => $rows,
'#prefix' => '<div class=upei-roblib-ill-biblio-info>',
'#suffix' => '</div>',
);
];
$html_output = drupal_render($output);
return $html_output;
}

106
upei_roblib_ill.install

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

485
upei_roblib_ill.module

@ -5,34 +5,34 @@
*/
function upei_roblib_ill_menu() {
$items = array();
$items = [];
$items['admin/settings/roblibill'] = array(
$items['admin/settings/roblibill'] = [
'title' => 'UPEI Roblib ILL settings',
'description' => 'Conifiguration for the UPEI ILL forms',
'page callback' => 'drupal_get_form',
'page arguments' => array('upei_roblib_ill_admin_form'),
'access arguments' => array('access administration pages'),
'page arguments' => ['upei_roblib_ill_admin_form'],
'access arguments' => ['access administration pages'],
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['upei/roblib/ill'] = array(
];
$items['upei/roblib/ill'] = [
'title' => 'UPEI ILL Form',
'description' => 'The entry point for the UPEI ILL forms',
'page callback' => 'drupal_get_form',
'page arguments' => array('upei_roblib_ill_form'),
'access arguments' => array('access content'),
'page arguments' => ['upei_roblib_ill_form'],
'access arguments' => ['access content'],
'file' => 'includes/form.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['upei/roblib/ill/finished'] = array(
];
$items['upei/roblib/ill/finished'] = [
'title' => 'UPEI ILL Request',
'description' => 'Redirect to this page after form is submitted',
'page callback' => 'upei_roblib_ill_form_redirect',
'access arguments' => array('access content'),
'access arguments' => ['access content'],
'file' => 'includes/form.inc',
'type' => MENU_NORMAL_ITEM,
);
];
return $items;
}
@ -41,6 +41,7 @@ function upei_roblib_ill_menu() {
*
* @param $form
* @param $form_state
*
* @return array
*/
function upei_roblib_ill_doi_callback($form, &$form_state) {
@ -53,10 +54,10 @@ function upei_roblib_ill_doi_callback($form, &$form_state) {
* Implements hook_views_api().
*/
function upei_roblib_ill_views_api() {
return array(
return [
'api' => 3,
'path' => drupal_get_path('module', 'upei_roblib_ill') . '/views',
);
];
}
/**
@ -64,402 +65,402 @@ function upei_roblib_ill_views_api() {
*/
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(
$data['upei_roblib_ill_request']['table']['base'] = [
'field' => 'id',
'title' => t('UPEI Roblib ILL Request'),
'help' => t('Table for logging ILL Request'),
'weight' => -10,
);
];
$data['upei_roblib_ill_request']['patron_id'] = array(
$data['upei_roblib_ill_request']['patron_id'] = [
'title' => t('Patron or Campus ID'),
'help' => t('Patron or Campus ID.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
],
];
$data['upei_roblib_ill_request']['id'] = array(
$data['upei_roblib_ill_request']['id'] = [
'title' => t('Unique ID for an ILL request'),
'help' => t('Unique ID for an ILL request.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
);
],
];
$data['upei_roblib_ill_request']['patron_email'] = array(
$data['upei_roblib_ill_request']['patron_email'] = [
'title' => t('Patron Email Address'),
'help' => t('Patron Email Address.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['patron_lastname'] = array(
],
];
$data['upei_roblib_ill_request']['patron_lastname'] = [
'title' => t('Patron Lastname'),
'help' => t('Patron Lastname.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
],
];
$data['upei_roblib_ill_request']['patron_firstname'] = array(
$data['upei_roblib_ill_request']['patron_firstname'] = [
'title' => t('Patron Firstame'),
'help' => t('Patron Firstname.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['patron_department'] = array(
],
];
$data['upei_roblib_ill_request']['patron_department'] = [
'title' => t('Patron Department'),
'help' => t('Patron Department.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['patron_type'] = array(
],
];
$data['upei_roblib_ill_request']['patron_type'] = [
'title' => t('Patron Type'),
'help' => t('Patron Type.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['author'] = array(
],
];
$data['upei_roblib_ill_request']['author'] = [
'title' => t('Authors name'),
'help' => t('Authors Fullname.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['title'] = array(
],
];
$data['upei_roblib_ill_request']['title'] = [
'title' => t('Book or Journal Title'),
'help' => t('Book or Patron Title.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['atitle'] = array(
],
];
$data['upei_roblib_ill_request']['atitle'] = [
'title' => t('Article or Chapter Title'),
'help' => t('Article or Chapter Title.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['issn'] = array(
],
];
$data['upei_roblib_ill_request']['issn'] = [
'title' => t('ISSN'),
'help' => t('ISSN.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['isbn'] = array(
],
];
$data['upei_roblib_ill_request']['isbn'] = [
'title' => t('ISBN'),
'help' => t('ISBN.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['article_author'] = array(
],
];
$data['upei_roblib_ill_request']['article_author'] = [
'title' => t('Article or Chapter author'),
'help' => t('Article or Chapter author.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['citation_date'] = array(
],
];
$data['upei_roblib_ill_request']['citation_date'] = [
'title' => t('The date of the article'),
'help' => t('Article Date.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['pages_requested'] = array(
],
];
$data['upei_roblib_ill_request']['pages_requested'] = [
'title' => t('The pages requested'),
'help' => t('The pages requested.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['volume'] = array(
],
];
$data['upei_roblib_ill_request']['volume'] = [
'title' => t('Volume'),
'help' => t('Volume.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['issue'] = array(
],
];
$data['upei_roblib_ill_request']['issue'] = [
'title' => t('Issue'),
'help' => t('Issue.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['genre'] = array(
],
];
$data['upei_roblib_ill_request']['genre'] = [
'title' => t('Article or Chapter author'),
'help' => t('Article or Chapter author.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['doi'] = array(
],
];
$data['upei_roblib_ill_request']['doi'] = [
'title' => t('DOI'),
'help' => t('DOI.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['relais_request_id'] = array(
],
];
$data['upei_roblib_ill_request']['relais_request_id'] = [
'title' => t('The Relais request id'),
'help' => t('The Relais request id.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['relais_message'] = array(
],
];
$data['upei_roblib_ill_request']['relais_message'] = [
'title' => t('The reason a request failed.'),
'help' => t('The reason a request failed.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
$data['upei_roblib_ill_request']['notes'] = array(
],
];
$data['upei_roblib_ill_request']['notes'] = [
'title' => t('The notes related to this request'),
'help' => t('The notes related to this request.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_string',
),
'argument' => array(
],
'argument' => [
'handler' => 'views_handler_argument_string',
),
);
],
];
$data['upei_roblib_ill_request']['time_submitted'] = array(
$data['upei_roblib_ill_request']['time_submitted'] = [
'title' => t('The Date and Time a request was submitted'),
'help' => t('The Date and Time a request was submitted.'),
'field' => array(
'field' => [
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
],
'sort' => [
'handler' => 'views_handler_sort_date',
),
'filter' => array(
],
'filter' => [
'handler' => 'views_handler_filter_date',
),
);
],
];
return $data;
}

Loading…
Cancel
Save