Browse Source

ebsco eds book block is now working results match the d7 version as well

d9
ppound 3 years ago
parent
commit
2de44ce697
  1. 108
      modules/roblib_search_eds/js/eds_results.js
  2. 112
      modules/roblib_search_eds/js/eds_results_book.js
  3. 19
      modules/roblib_search_eds/roblib_search_eds.libraries.yml
  4. 122
      modules/roblib_search_eds/roblib_search_eds.module
  5. 19
      modules/roblib_search_eds/roblib_search_eds.routing.yml
  6. 95
      modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php
  7. 23
      modules/roblib_search_eds/src/Form/EdsSettingsForm.php
  8. 29
      modules/roblib_search_eds/src/Lib/EBSCOAPI.php
  9. 6
      modules/roblib_search_eds/src/Lib/EBSCOConnector.php
  10. 32
      modules/roblib_search_eds/src/Lib/EBSCOResponse.php
  11. 20
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php
  12. 3
      modules/roblib_search_eds/templates/roblib-search-eds-books.html.twig
  13. 4
      modules/roblib_search_eds/templates/theme.inc

108
modules/roblib_search_eds/js/eds_results.js

@ -1,108 +0,0 @@
Drupal.behaviors.roblib_search_eds = {
attach: function (context, settings) {
$url = settings.roblib_search_eds.search_url;
profile = settings.roblib_search_eds.eds_profile;
proxy_url = "https://proxy.library.upei.ca/login?url=";
jQuery.getJSON($url, function (data) {
var items = [];
var numberOfDocs = 0;
try {
numberOfDocs = data.numFound;
} catch (err) {
// do nothing leave docLength at 0
}
if (numberOfDocs < 1) {
jQuery('#' + 'roblib-search-content-eds').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-eds-roblib-search-eds-results').hide();
} else {
var counter = 0;
var divs = new Array();
var content = new Array();
var queries = [];
jQuery.each(data.queries, function (key7, query) {
queries.push(query.query);
})
var query_str = encodeURI(data.queries[0].query);
var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profid=lite&mode=bool&lang=en&bquery=';
jQuery.each(data.documents, function (key, val) {
id = 'roblib-search-eds-' + counter;
divs[counter++] = id;
if (typeof val.Items !== 'undefined') {
items.push('<div class ="roblib-search-row" id="' + id + '">');
if (typeof val.Items.Title !== 'undefined') {
items.push('<div class="roblib-title eds">');
items.push('<a href="' + proxy_url + val.PLink + '&scope=site">' + val.Items.Title.Data + '</a></div>');
}
val.PubType == 'Book' ? pubType = 'Print Book' : pubType = val.PubType;
pubYear = val.RecordInfo.BibRelationships.IsPartOfRelationships["date"];
!pubYear ? pubYear = " " : pubYear = pubYear[0]["Y"];
items.push('<div class="eds-type"><span class="eds-pubyear">' + pubYear + '</span> - ' + pubType + '</div>');
var roblib_authors =[];
jQuery.each(val.RecordInfo.BibRelationships.HasContributorRelationships, function (key3, author) {
roblib_authors.push(author.NameFull);
})
items.push('<div class="eds-sor">');
roblib_authors = roblib_shorten(roblib_authors.join('; '), 50, " ");
items.push(roblib_authors);
items.push('</div>');
var url;
!val.Items.URL ? url = " " : url = val.Items.URL.Data;
if(url) {
items.push('<div class="eds-url">' + url + '</div>');
}
if(pubType == "Print Book") {
anNumber = val.An.split(".");
if (anNumber[0] && anNumber[0] == 'upei') {
catalogUrl = '<a href="http://islandpines.roblib.upei.ca/eg/opac/record/' + anNumber[1] +
'">View in UPEI Catalogue</a>';
items.push('<div class="eds-catalog-link">' + catalogUrl + '</div>');
}
}
items.push('</div>');
} else {
items.push('<div class ="roblib-search-row roblib-eds-unauthorized" id="\' + id + \'">You must login to view this result, <a href="https://proxy.library.upei.ca/login?url=' + href_str + query_str + '" id="eds-unauthorized-result">click here to login</a></div>' );
}
});
jQuery('#' + 'roblib-search-content-eds').empty().append(items.join(''));
}
var non_upei_link = '';
var upei_link = '<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results">SEE ALL (' + data.recordCount + ')</a> ';
if(!data.is_local_ip) {
non_upei_link = '<a href="' + href_str + query_str + '&authtype=ip,guest" id="eds-non-upei-see_all_results">[Non-UPEI]</a>';
upei_link = upei_link + non_upei_link;
}
jQuery('#roblib-search-eds-more').empty().append(upei_link);
jQuery('#roblib-eds-books-more-results').empty().append(upei_link);
jQuery('#roblib-eds-books-toc').empty().append('<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results-toc">Books (' + data.recordCount + ')</a>');
});
}
}
function roblib_intersects(a, b) {
var d = {};
var results = [];
for (var i = 0; i < b.length; i++) {
d[b[i]] = true;
}
for (var j = 0; j < a.length; j++) {
if (d[a[j]])
results.push(a[j]);
}
return results;
}
function roblib_shorten(str, maxLen, separator) {
if (str.length <= maxLen) return str;
return str.substr(0, str.lastIndexOf(separator, maxLen)) + ' et al.';
}

112
modules/roblib_search_eds/js/eds_results_book.js

@ -0,0 +1,112 @@
Drupal.behaviors.roblib_search_eds = {
attach: function (context, settings) {
if (context == document) {
$query = $current_path.replace('roblib_search/', '');
$url = settings.eds_book_search_url + $query;
profile = settings.eds_book_profile;
proxy_url = "https://proxy.library.upei.ca/login?url=";
jQuery.getJSON($url, function (data) {
var items = [];
var numberOfDocs = 0;
try {
numberOfDocs = data.numFound;
} catch (err) {
// do nothing leave docLength at 0
}
if (numberOfDocs < 1) {
jQuery('#' + 'roblib-search-content-eds').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-eds-roblib-search-eds-results').hide();
} else {
var counter = 0;
var divs = new Array();
var content = new Array();
var queries = [];
jQuery.each(data.queries, function (key7, query) {
queries.push(query.query);
})
var query_str = encodeURI(data.queries[0].query);
var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profid=lite&mode=bool&lang=en&bquery=';
jQuery.each(data.documents, function (key, val) {
id = 'roblib-search-eds-' + counter;
divs[counter++] = id;
if (typeof val.Items !== 'undefined') {
items.push('<div class ="roblib-search-row" id="' + id + '">');
if (typeof val.Items.Title !== 'undefined') {
items.push('<div class="roblib-title eds">');
items.push('<a href="' + proxy_url + val.PLink + '&scope=site">' + val.Items.Title.Data + '</a></div>');
}
val.PubType == 'Book' ? pubType = 'Print Book' : pubType = val.PubType;
pubYear = val.RecordInfo.BibRelationships.IsPartOfRelationships["date"];
!pubYear ? pubYear = " " : pubYear = pubYear[0]["Y"];
items.push('<div class="eds-type"><span class="eds-pubyear">' + pubYear + '</span> - ' + pubType + '</div>');
var roblib_authors = [];
jQuery.each(val.RecordInfo.BibRelationships.HasContributorRelationships, function (key3, author) {
roblib_authors.push(author.NameFull);
})
items.push('<div class="eds-sor">');
roblib_authors = roblib_shorten(roblib_authors.join('; '), 50, " ");
items.push(roblib_authors);
items.push('</div>');
var url;
!val.Items.URL ? url = " " : url = val.Items.URL.Data;
if (url) {
items.push('<div class="eds-url">' + url + '</div>');
}
if (pubType == "Print Book") {
anNumber = val.An.split(".");
if (anNumber[0] && anNumber[0] == 'upei') {
catalogUrl = '<a href="http://islandpines.roblib.upei.ca/eg/opac/record/' + anNumber[1] +
'">View in UPEI Catalogue</a>';
items.push('<div class="eds-catalog-link">' + catalogUrl + '</div>');
}
}
items.push('</div>');
} else {
items.push('<div class ="roblib-search-row roblib-eds-unauthorized" id="\' + id + \'">You must login to view this result, <a href="https://proxy.library.upei.ca/login?url=' + href_str + query_str + '" id="eds-unauthorized-result">click here to login</a></div>');
}
});
jQuery('#' + 'roblib-search-content-eds').empty().append(items.join(''));
}
var non_upei_link = '';
var upei_link = '<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results">SEE ALL (' + data.recordCount + ')</a> ';
if (!data.is_local_ip) {
non_upei_link = '<a href="' + href_str + query_str + '&authtype=ip,guest" id="eds-non-upei-see_all_results">[Non-UPEI]</a>';
upei_link = upei_link + non_upei_link;
}
jQuery('#roblib-search-eds-more').empty().append(upei_link);
jQuery('#roblib-eds-books-more-results').empty().append(upei_link);
jQuery('#roblib-eds-books-toc').empty().append('<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results-toc">Books (' + data.recordCount + ')</a>');
});
}
}
}
function roblib_intersects(a, b) {
var d = {};
var results = [];
for (var i = 0; i < b.length; i++) {
d[b[i]] = true;
}
for (var j = 0; j < a.length; j++) {
if (d[a[j]])
results.push(a[j]);
}
return results;
}
function roblib_shorten(str, maxLen, separator) {
if (str.length <= maxLen)
return str;
return str.substr(0, str.lastIndexOf(separator, maxLen)) + ' et al.';
}

19
modules/roblib_search_eds/roblib_search_eds.libraries.yml

@ -0,0 +1,19 @@
eds-book:
version: 1.x
css:
base:
css/roblib_search_eds.css: {}
js:
js/eds_results_book.js: {}
dependencies:
- core/drupal
eds-article:
version: 1.x
css:
base:
css/roblib_search_eds.css: {}
js:
js/eds_results_article.js: {}
dependencies:
- core/drupal

122
modules/roblib_search_eds/roblib_search_eds.module

@ -78,49 +78,21 @@ function roblib_search_eds_info($type = 'Articles') {
* Implements hook_theme().
*/
function roblib_search_eds_theme($existing, $type, $theme, $path) {
$modulePath = \Drupal::service('module_handler')->getModule('roblib_search')
->getPath();
$spinner_path = '/' . $modulePath . "/img/spinner.gif";
return [
'roblib_search_eds_books' => [
'variables' => ['query' => NULL],
'variables' => ['query' => NULL, 'spinner_path' => $spinner_path],
],
'roblib_search_eds_articles' => [
'variables' => ['query' => NULL],
'variables' => ['query' => NULL, 'spinner_path' => $spinner_path],
],
];
}
/*function roblib_search_eds_block_info() {
$blocks['roblib_search_eds_results'] = array(
// info: The name of the block.
'info' => t('EDS Search Results block'),
// Block caching options (per role, per user, etc.)
'cache' => DRUPAL_CACHE_PER_ROLE,
);
$blocks['roblib_search_eds_articles'] = array(
'info' => t('EDS Search Results Articles'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
return $blocks;
}*/
/*function roblib_search_eds_block_view($delta = '') {
switch ($delta) {
case 'roblib_search_eds_results':
$block['subject'] = t('Books & Media');
$block['content'] = theme('roblib_search_eds', array('results' => NULL));
break;
case 'roblib_search_eds_articles':
$block['subject'] = t('Articles');
$block['content'] = theme('roblib_search_eds_articles', array('results' => NULL));
break;
}
return $block;
}*/
/*function roblib_search_eds_ajax($query) {
print roblib_search_eds_get_results($query, 'Books');
exit();
@ -131,47 +103,7 @@ function roblib_search_eds_articles($query) {
exit();
}*/
/**
*
* @param string $query
* @return string
* json string
*/
function roblib_search_eds_get_results($query = NULL, $type = 'Articles') {
drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
module_load_include('php', 'ebsco', 'lib/EBSCOAPI');
module_load_include('php', 'ebsco', 'lib/EBSCOAPIConnector');
module_load_include('php', 'ebsco', 'lib/EBSCOAPIResponse');
// Url parameters.
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
}
}
$limiters = '';
if ($type != NULL) {
$limiters = urldecode(roblib_search_eds_get_query_limiters($type));
}
// hardcoding "available in library collection" limiter as we can't pass it the
// same way we passed other limiters
$filters = ($type === 'Books') ? array("addlimiter(FT1:y)") : array();
$config = roblib_search_eds_build_config_arr($type);
$number_per_page = variable_get('roblib_search_eds_num_results', '5');
$query = '(' . $query . ') ' . $limiters;
$search = array('lookfor' => $query, 'type' => 'ALLFields', 'index' => 'AllFields', 'q' => 'ebsco/results', 'op' => 'Search');
$eds_api = new EBSCOAPI($config);
$is_local_ip = $eds_api->connector()->isGuestIPAddress($_SERVER["REMOTE_ADDR"]);
//$eds_api->isGuest(boolval(variable_get('roblib_search_eds_guest','y')));
$eds_api->isGuest(!$is_local_ip);
$output = $eds_api->apiSearch($search, $filters, 1, $number_per_page);
$output['is_local_ip'] = $is_local_ip;
return json_encode($output);
}
/**
* For each result query ebsco again to get the detailed record.
@ -194,50 +126,6 @@ function roblib_search_eds_get_detailed_result(&$output, $query, &$eds_api) {
}
}
/**
* Creates the limiter string to append to the end of a query.
*
* @param string $type
* The type of search we want (Articles or Books)
*
* @return string
* The limiters to append to the query.
*/
function roblib_search_eds_get_query_limiters($type) {
$limiters = 'n';
switch ($type) {
case 'Articles':
//$limiters = 'facetfilter=1,SourceType:Magazines,SourceType:News,SourceType:Academic+Journals,SourceType:Conference+Materials';
$limiters = ' ' . variable_get('roblib_search_eds_article_limiters',
'AND (PT Article OR PT Magazines OR PT News OR PT Academic Journals OR PT Conference Materials)');
break;
case 'Books':
// $limiters = '+AND+(PT+book)';
//$limiters = 'facetfilter=1,PublicationType:Books,PublicationType:Audio,PublicationType:Videos';
$limiters = ' ' . variable_get('roblib_search_eds_book_limiters',
'AND (PT Book OR PT Video OR PT Audio)');
break;
}
return urlencode($limiters);
}
function roblib_search_eds_build_config_arr($type) {
$config = array();
$config['user'] = variable_get('roblib_search_eds_user', 'edsusername');
$config['password'] = variable_get('roblib_search_eds_pass', 'edspassword');
//get the local ips allowed from ebsco
$config['local_ip_address'] = variable_get('ebsco_local_ips');
$config['profile'] = ($type === 'Books') ? variable_get('roblib_search_eds_book_profile', 'apilite') :
variable_get('roblib_search_eds_profile', 'edsapi');
$config['auth_url'] = variable_get('roblib_search_eds_auth_url', 'https://eds-api.ebscohost.com/Authservice/rest');
$config['rest_url'] = variable_get('roblib_search_eds_rest_url', 'https://eds-api.ebscohost.com/edsapi/rest');
$config['guest'] = variable_get('roblib_search_eds_guest','y');
return $config;
}
/**
* Implements hook_help().
*

19
modules/roblib_search_eds/roblib_search_eds.routing.yml

@ -5,4 +5,21 @@ roblib_search_eds.settings:
_title: 'Roblib Search EDS Settings Form'
requirements:
_permission: 'administer site configuration'
roblib_search_eds.article_search:
path: '/roblib_search/eds/articles/{query}'
defaults:
_controller: '\Drupal\roblib_search_eds\Controller\RoblibSearchEdsController::articleResults'
_title: 'Roblib Search EDS Articles'
query: '[a-zA-Z\s]+'
requirements:
_permission: 'access content'
roblib_search_eds.book_search:
path: '/roblib_search/eds/book/{query}'
defaults:
_controller: '\Drupal\roblib_search_eds\Controller\RoblibSearchEdsController::bookResults'
_title: 'Roblib Search EDS Articles'
query: '[a-zA-Z\s]+'
requirements:
_permission: 'access content'

95
modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php

@ -3,6 +3,7 @@
namespace Drupal\roblib_search_eds\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\roblib_search_eds\Lib\EBSCOAPI;
/**
* Controller for d3 graphs.
@ -16,9 +17,11 @@ class RoblibSearchEdsController extends ControllerBase {
* A renderable array.
*/
public function articleResults($query = NULL) {
print $this->eds_get_results($query, 'Articles');
exit();
}
/**
* Display the markup.
*
@ -26,10 +29,92 @@ class RoblibSearchEdsController extends ControllerBase {
* A renderable array.
*/
public function bookResults($query = NULL) {
return [
'#theme' => 'roblib_search_eds_books',
'#query' => $query,
];
print $this->eds_get_results($query, 'Books');
exit();
}
/**
*
* @param string $query
* @return string
* json string
*/
function eds_get_results($query = NULL, $type = 'Articles') {
//drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
$config = \Drupal::config('roblib_search_eds.settings');
// Url parameters.
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
}
}
$limiters = '';
if ($type != NULL) {
$limiters = $this->get_eds_query_limiters($type);
}
// hardcoding "available in library collection" limiter as we can't pass it the
// same way we passed other limiters
$filters = ($type === 'Books') ? array("addlimiter(FT1:y)") : array();
$eds_config = $this->build_eds_config_arr($type);
$number_per_page = $config->get('eds_num_results');
$query = '(' . $query . ') ' . $limiters;
$search = array('lookfor' => $query, 'type' => 'ALLFields', 'index' => 'AllFields', 'q' => 'ebsco/results', 'op' => 'Search');
$eds_api = new EBSCOAPI($eds_config);
$is_local_ip = $eds_api->connector()->isGuestIPAddress($_SERVER["REMOTE_ADDR"]);
$eds_api->isGuest(!$is_local_ip);
$output = $eds_api->apiSearch($search, $filters, 1, $number_per_page);
$output['is_local_ip'] = $is_local_ip;
print json_encode($output);
exit();
}
/**
* Creates the limiter string to append to the end of a query.
*
* @param string $type
* The type of search we want (Articles or Books)
*
* @return string
* The limiters to append to the query.
*/
function get_eds_query_limiters($type) {
$config = \Drupal::config('roblib_search_eds.settings');
$limiters = 'n';
switch ($type) {
case 'Articles':
//example 'facetfilter=1,SourceType:Magazines,SourceType:News,SourceType:Academic+Journals,SourceType:Conference+Materials';
$limiters = ' ' . $config->get('eds_article_limiters');
break;
case 'Books':
// example '+AND+(PT+book)';
// example 'facetfilter=1,PublicationType:Books,PublicationType:Audio,PublicationType:Videos';
$limiters = ' ' . $config->get('eds_book_limiters');
break;
}
return $limiters;
}
function build_eds_config_arr($type) {
$ebsco_config = array();
$roblib_search_config = \Drupal::config('roblib_search_eds.settings');
$ebsco_config['user'] = $roblib_search_config->get('eds_user');
$ebsco_config['password'] = $roblib_search_config->get('eds_pass');
//get the local ips allowed from ebsco
//TODO move this to a variable
$ebsco_config['local_ip_address'] = $roblib_search_config->get('eds_local_ip');
$ebsco_config['profile'] = ($type === 'Books') ? $roblib_search_config->get
('eds_book_profile') : $roblib_search_config->get('eds_article_profile');
$ebsco_config['auth_url'] = $roblib_search_config->get('eds_auth_url');
$ebsco_config['rest_url'] = $roblib_search_config->get('eds_rest_url');
$ebsco_config['guest'] = $roblib_search_config->get('eds_guest');
$ebsco_config['autocomplete'] = '';
return $ebsco_config;
}
}

23
modules/roblib_search_eds/src/Form/EdsSettingsForm.php

@ -24,7 +24,7 @@ class EdsSettingsForm extends FormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::config('roblib_search_eds.settings');
$form['eds_rest_url'] = array(
/* $form['eds_rest_url'] = array(
'#type' => 'textfield',
'#title' => t('EDS Rest endpoint'),
'#default_value' => $config->get('eds_rest_url'),
@ -61,8 +61,16 @@ class EdsSettingsForm extends FormBase {
'#default_value' => $config->get('eds_guest'),
'#description' => t('EDS Guest access, y = guest access, n = not a guest'),
'#required' => TRUE,
);*/
$form['eds_local_ip'] = array(
'#type' => 'textfield',
'#title' => t('EDS Local IP'),
'#default_value' => $config->get('eds_local_ip'),
'#description' => t('Local IP address prefix, i. 137.149.'),
'#required' => TRUE,
);
$form['eds_article_profile'] = array(
'#type' => 'textfield',
'#title' => t('EDS Article profile'),
@ -122,11 +130,12 @@ class EdsSettingsForm extends FormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()->getEditable('roblib_search_eds.settings');
$config->set('eds_rest_url', $form_state->getValue('eds_rest_url'))->save();
$config->set('eds_auth_url', $form_state->getValue('eds_auth_url'))->save();
$config->set('eds_user', $form_state->getValue('eds_user'))->save();
$config->set('eds_pass', $form_state->getValue('eds_pass'))->save();
$config->set('eds_guest', $form_state->getValue('eds_guest'))->save();
//$config->set('eds_rest_url', $form_state->getValue('eds_rest_url'))->save();
//$config->set('eds_auth_url', $form_state->getValue('eds_auth_url'))->save();
//$config->set('eds_user', $form_state->getValue('eds_user'))->save();
//$config->set('eds_pass', $form_state->getValue('eds_pass'))->save();
//$config->set('eds_guest', $form_state->getValue('eds_guest'))->save();
$config->set('eds_local_ip', $form_state->getValue('eds_local_ip'))->save();
$config->set('eds_article_profile', $form_state->getValue('eds_article_profile'))->save();
$config->set('eds_book_profile', $form_state->getValue('eds_book_profile'))->save();
$config->set('eds_num_results', $form_state->getValue('eds_num_results'))->save();

29
modules/roblib_search_eds/src/Lib/EBSCOAPI.php

@ -273,13 +273,14 @@ class EBSCOAPI {
* @access protected
*/
protected function request($action, $params = NULL, $attempts = 5) {
$authenticationToken = $this->authenticationToken();
$sessionToken = $this->sessionToken();
//$authenticationToken = $this->authenticationToken();
$sessionToken = $this->apiSessionToken();//$this->sessionToken();
// If authentication token is missing then the session token is missing too, so get both tokens
// If session token is missing then the authentication token may be invalid, so get both tokens.
if (empty($authenticationToken) || empty($sessionToken)) {
$result = $this->apiAuthenticationAndSessionToken();
if (empty($sessionToken)) {
//$result = $this->apiAuthenticationAndSessionToken();
$result = $this->apiSessionToken();
if ($this->isError($result)) {
// Any error should terminate the request immediately
// in order to prevent infinite recursion.
@ -295,7 +296,7 @@ class EBSCOAPI {
}
$headers = array(
'x-authenticationToken: '.$this->authenticationToken(),
// 'x-authenticationToken: '.$this->authenticationToken(),
'x-sessionToken: '.$this->sessionToken(),
);
@ -366,9 +367,9 @@ class EBSCOAPI {
*/
public function apiSessionToken() {
// Add authentication tokens to headers.
$headers = array(
'x-authenticationToken: '.$this->authenticationToken(),
);
//$headers = array(
// 'x-authenticationToken: '.$this->authenticationToken(),
//);
$response = $this->connector()->requestSessionToken($headers);
// Raise the exception so that any code running this method should exit immediately.
@ -592,12 +593,12 @@ class EBSCOAPI {
'highlight' => 'y',
'includeimagequickview' => $includeimagequickview,
//'includeimagequickview' => $includeimagequickview,
'format' => 'ris',
'styles' => $styles,
//UPEI commented out
//'format' => 'ris',
//UPEI commented out
//'styles' => $styles,
);
@ -620,7 +621,7 @@ class EBSCOAPI {
}
if ($includeimagequickview == TRUE) {
$params["includeimagequickview"] = "y";
//$params["includeimagequickview"] = "y";
}
if ($styles == 'all') {

6
modules/roblib_search_eds/src/Lib/EBSCOConnector.php

@ -272,9 +272,9 @@ class EBSCOConnector {
.'<UserId>'.$this->userId.'</UserId>'
.'<Password>'.$this->password.'</Password>'
.'<InterfaceId>wsapi</InterfaceId>'
.'<Options>
<Option>'.$this->autoComplete.'</Option>
</Options>'
// .'<Options>
// <Option>'.$this->autoComplete.'</Option>
// </Options>'
.'</UIDAuthRequestMessage>';
$response = $this->request($url,$params, array(), 'POST');

32
modules/roblib_search_eds/src/Lib/EBSCOResponse.php

@ -20,8 +20,8 @@ namespace Drupal\roblib_search_eds\Lib;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use Drupal\roblib_search_eds\Lib\HTML_Sanitizer;
require_once __DIR__ . '/sanitizer.class.php';
//use Drupal\roblib_search_eds\Lib\HTML_Sanitizer;
/**
* EBSCOResponse class.
@ -168,6 +168,17 @@ class EBSCOResponse
$result = json_decode(json_encode($this->response->SearchResult->citationStylesTerms), true);
$citationStylesTerms = $result;
}
// added by UPEI so we can link back with exact same search.
$queries = array();
if($this->response->SearchRequestGet->SearchCriteriaWithActions->QueriesWithAction){
$queriesWithAction = $this->response->SearchRequestGet->SearchCriteriaWithActions->QueriesWithAction->QueryWithAction;
foreach($queriesWithAction as $queryWithAction){
$queries[]=array(
'query' => (string)$queryWithAction->Query->Term,
'removeAction'=> (string) $queryWithAction->RemoveAction
);
}
}
$results = array(
'recordCount' => $hits,
@ -180,6 +191,7 @@ class EBSCOResponse
'facets' => $facets,
'imageQuickViewTerms' => $imageQuickViewTerms,
'citationStylesTerms' => $citationStylesTerms,
'queries' => $queries,
);
return $results;
@ -573,16 +585,16 @@ class EBSCOResponse
//ImageQuickView
//ImageQuickView UPEI commented out below code.
$includeImageQuickView = array();
$elements = $this->response->AvailableIncludeImageQuickView->IncludeImageQuickViewOptions->IncludeImageQuickViewOption;
/*$elements = $this->response->AvailableIncludeImageQuickView->IncludeImageQuickViewOptions->IncludeImageQuickViewOption;
foreach ($this->response->ViewResultSettings->IncludeImageQuickView as $element) {
$includeImageQuickView[] = array(
'Label' => (string) $element->Label,
'Id' => (string) $element->Id,
'DefaultOn' => (string) $element->DefaultOn,
);
}
}*/
@ -937,7 +949,7 @@ class EBSCOResponse
// Any group can be added here, but we only use Au (Author)
// Other groups, not present here, won't be transformed to HTML links.
$allowed_searchlink_groups = array('au');
$allowed_link_groups = array('URL', 'url');
// Map xml tags to the HTML tags
// This is just a small list, the total number of xml tags is far more greater.
$xml_to_html_tags = array(
@ -1015,6 +1027,14 @@ class EBSCOResponse
$data = str_replace('</searchLink>', '</a>', $data);
}
}
// Parse link
if (!empty($group) && in_array($group, $allowed_link_groups)) {
$link_xml = '/<link linkTarget="([^"]*)" linkTerm="([^"]*)" linkWindow="([^"]*)">/';
$link_html = "<a name=\"$1\" href=\"$2\" target=\"$3\">"; //replaced $path with "result.php"
$data = preg_replace($link_xml, $link_html, $data);
$data = str_replace('</link>', '</a>', $data);
}
// Replace the rest of searchLinks with simple spans.
$link_xml = '/<searchLink fieldCode="([^\"]*)" term="%22([^\"]*)%22">/';

20
modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php

@ -19,9 +19,25 @@ class RoblibSearchEdsBooks extends BlockBase {
* {@inheritdoc}
*/
public function build() {
return [
$host = \Drupal::request()->getSchemeAndHttpHost();
$search_url = $host . '/roblib_search/eds/book/';
$eds_profile = \Drupal::config('roblib_search_eds.settings')
->get('eds_book_profile');
$settings = [
'eds_book_search_url' => $search_url,
'eds_book_profile' => $eds_profile,
];
return [
'#theme' => 'roblib_search_eds_books',
'#query' => $query,
'query' => $query,
'spinner_path' => 'test',
'#attached' => [
'library' => [
'roblib_search_eds/eds-book'
],
'drupalSettings' => $settings,
],
];
}
}

3
modules/roblib_search_eds/templates/roblib-search-eds-books.html.twig

@ -1,7 +1,6 @@
<div class ="roblib-search-more" id="roblib-search-eds-more"></div>
<div class ="roblib-search-content eds" id="roblib-search-content-eds">
<img src="{{ spinner_path }}"/>
</div>
<div id="roblib-eds-books-more-results" class="roblib-eds-more-button button"></div>
<div id="roblib-eds-books-toc" class="roblib-bento-toc moveme-please"></div>

4
modules/roblib_search_eds/templates/theme.inc

@ -8,7 +8,7 @@
// TODO: combine these two functions and call this function from the preprocessor
function roblib_search_eds_preprocess_roblib_search_eds(&$variables) {
global $base_url;
/*global $base_url;
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
@ -28,6 +28,8 @@ function roblib_search_eds_preprocess_roblib_search_eds(&$variables) {
variable_get('roblib_search_eds_book_profile', 'apilite')
)
), array('type' => 'setting'));
* */
}

Loading…
Cancel
Save