Browse Source

added new eds target for articles

2.x-ebsco
Paul Pound 11 years ago
parent
commit
329c501122
  1. 2
      targets/cufts/roblib_search_cufts.module
  2. 64
      targets/eds/js/eds_results_article.js
  3. 87
      targets/eds/roblib_search_eds.module
  4. 19
      targets/eds/theme/roblib-search-eds-articles.tpl.php
  5. 25
      targets/eds/theme/theme.inc

2
targets/cufts/roblib_search_cufts.module

@ -139,7 +139,7 @@ function roblib_search_cufts_block_view($delta = '') {
// The subject is displayed at the top of the block. Note that it
// should be passed through t() for translation. The title configured
// for the block using Drupal UI supercedes this one.
$block['subject'] = t('Cufts Results');
$block['subject'] = t('Journals');
// The content of the block is typically generated by calling a custom
// function.
// $block['content'] = roblib_search_cufts_get_results();

64
targets/eds/js/eds_results_article.js

@ -0,0 +1,64 @@
Drupal.behaviors.roblib_search_eds_articles = {
attach: function(context, settings) {
$url = settings.roblib_search_eds_articles.search_url;
jQuery.getJSON($url, function(data) {
var items = [];
var numberOfDocs = 0;
try {
numberOfDocs = data.records.length;
} 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-articles').hide();
} else {
jQuery.each(data.records, function(key, val) {
//items.push('<a class="roblib-search-eds-tn" href="'+val.ImageInfo.thumb+'"/>');
//jQuery.each(val.RecordInfo.BibEntity.Titles, function(key2, val2){
if (typeof val.Items !== 'undefined') {
items.push('<div class ="roblib-search-row">');
if (typeof val.Items.Ti !== 'undefined') {
jQuery.each(val.Items.Ti, function(key2, val2){
items.push('<div class="roblib-title eds">');
items.push('<a href="'+val.PLink+'">'+val2.Data+'</a></div>');
})
}
jQuery.each(val.RecordInfo.BibRelationships.HasContributorRelationships, function(key3, authors){
items.push('<div class="eds-sor">'+authors.NameFull+'</div>');
})
if (typeof val.Items.Src !== 'undefined') {
jQuery.each(val.Items.Src, function(key4, source){
items.push('<div class="eds-src">'+source.Data+'</div>');
})
}
if (typeof val.Items.PubIrInfo !== 'undefined') {
jQuery.each(val.Items.PubIrInfo, function(key5, pubinfo){
items.push('<div class="eds-pubinfo">'+pubinfo.Data+'</div>');
})
}
if (typeof val.Items.TypPub !== 'undefined') {
jQuery.each(val.Items.TypPub, function(key6, typpub){
items.push('<div class="eds-type">'+typpub.Data+'</div>');
})
}
items.push('<div class="eds-db">'+val.DbLabel+'</div>');
items.push('</div>');
}
});
}
jQuery('#' + 'roblib-search-content-eds-articles').empty().append(items.join(''));
var queries = [];
jQuery.each(data.queries, function(key7, query){
queries.push(query.query);
})
var query_str = data.queries[0].query;
var href_str = 'http://search.ebscohost.com/login.aspx?direct=true&site=ehost-live&scope=site&type=1&custid=uprince&groupid=main&profid=eds&mode=bool&lang=en&bquery=';
jQuery('#roblib-search-eds-more').empty().append('<a href="'+href_str+query_str+'" id="see_all_results">See all ' + data.recordCount + ' results</a>');
});
}
}

87
targets/eds/roblib_search_eds.module

@ -8,30 +8,6 @@ require_once dirname(__FILE__) . '/includes/rest/EBSCOConnector.php';
require_once dirname(__FILE__) . '/includes/rest/EBSCOResponse.php';
require_once dirname(__FILE__) . '/includes/rest/EBSCOConnector.php';
/**
* Implements hook_boot().
* @global type $conf
*/
function roblib_search_eds_boot() {
/* below is an example from islandora_solr module for internationalization
* global $conf;
// Allow i18n, by using multilingual variables.
if (module_exists('i18n')) {
$vars = array(
'islandora_solr_facets',
'islandora_solr_result_fields',
'islandora_solr_searchterms'
);
if (isset($conf['i18n_variables']) && is_array($conf['i18n_variables'])) {
$conf['i18n_variables'] = array_merge($vars, $conf['i18n_variables']);
}
else {
$conf['i18n_variables'] = $vars;
}
} */
}
/**
* Implements hook_menu().
@ -55,6 +31,13 @@ function roblib_search_eds_menu() {
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib eds'),
);
$items['roblib_search/eds/articles/%'] = array(
'title' => 'eds ajax',
'page callback' => 'roblib_search_eds_articles',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib eds'),
);
$items['roblib_search/eds/info'] = array(
'title' => 'eds info',
@ -158,7 +141,13 @@ function roblib_search_eds_theme() {
'file' => $file,
'template' => 'roblib-search-eds',
'variables' => array('results' => NULL),
)
),
'roblib_search_eds_articles' => array(
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-eds-articles',
'variables' => array('results' => NULL),
),
);
}
@ -168,31 +157,44 @@ function roblib_search_eds_block_info() {
// 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, // default
'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 = '') {
//The $delta parameter tells us which block is being requested.
switch ($delta) {
case 'roblib_search_eds_results':
// The subject is displayed at the top of the block. Note that it
// should be passed through t() for translation. The title configured
// for the block using Drupal UI supercedes this one.
$block['subject'] = t('EDS Results');
$block['subject'] = t('Books & Media');
// The content of the block is typically generated by calling a custom
// function.
// $block['content'] = roblib_search_eds_get_results();
$block['content'] = theme('roblib_search_eds', array('results' => NULL)); //we will get the results via javascript
$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);
print roblib_search_eds_get_results($query, 'Books');
exit();
}
function roblib_search_eds_articles($query){
print roblib_search_eds_get_results($query, 'Articles');
exit();
}
@ -202,7 +204,7 @@ function roblib_search_eds_ajax($query) {
* @return string
* json string
*/
function roblib_search_eds_get_results($query = NULL) {
function roblib_search_eds_get_results($query = NULL, $type = NULL) {
drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
// Url parameters.
@ -214,16 +216,35 @@ function roblib_search_eds_get_results($query = NULL) {
return '';
}
}
$limiters = '';
if($type != NULL){
$limiters = roblib_search_eds_get_query_limiters($type);
}
$config = roblib_search_eds_build_config_arr();
$eds_api = new EBSCOAPI($config);
$number_per_page = variable_get('roblib_search_eds_num_results', '5');
$query = urlencode($query);
$query = trim($query . $limiters);
$params = "query=AND,$query&includefacets=n&resultsperpage=$number_per_page";
$output = $eds_api->apiSearch($params);
return json_encode($output);
}
function roblib_search_eds_get_query_limiters($type){
$limiters = 'n';
switch ($type) {
case 'Articles':
$limiters = '+AND+(ZT+article)';
break;
case 'Books':
$limiters = '+AND+(PT+book)';
break;
}
return $limiters;
}
function roblib_search_eds_build_config_arr() {
$config = array();
$config['user'] = variable_get('roblib_search_eds_user', 'edsusername');

19
targets/eds/theme/roblib-search-eds-articles.tpl.php

@ -0,0 +1,19 @@
<?php
/**
* @file roblib-search-eds-article.tpl.php
* Search ebscohost for articles
*
* Variables available:
* - $variables: all array elements of $variables can be used as a variable. e.g. $base_url equals $variables['base_url']
*
*
* @see template_preprocess_roblib_search_wrapper()
*/
?>
<div class ="roblib-search-content eds-article" id="roblib-search-content-eds-articles">
<img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
</div>
<div class ="roblib-search-more" id="roblib-search-eds-article-more"></div>

25
targets/eds/theme/theme.inc

@ -1,7 +1,7 @@
<?php
/*
* all we do her is pass a url to some javascript so the results can be
* all we do here is pass a url to some javascript so the results can be
* loaded async
*/
@ -15,11 +15,30 @@ function roblib_search_eds_preprocess_roblib_search_eds(&$variables) {
return '';
}
}
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/'.'spinner.gif';
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/' . 'spinner.gif';
$variables['spinner_path'] = $spinner_path;
$search_url = $base_url .'/roblib_search/eds/ajax/'.urlencode($query);
$search_url = $base_url . '/roblib_search/eds/ajax/' . urlencode($query);
drupal_add_js(drupal_get_path('module', 'roblib_search_eds') . '/js/eds_results.js');
drupal_add_js(array('roblib_search_eds' => array('search_url' => $search_url)), array('type' => 'setting'));
}
function roblib_search_eds_preprocess_roblib_search_eds_articles(&$variables) {
global $base_url;
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
}
}
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/' . 'spinner.gif';
$variables['spinner_path'] = $spinner_path;
$search_url = $base_url . '/roblib_search/eds/articles/' . urlencode($query);
drupal_add_js(drupal_get_path('module', 'roblib_search_eds') . '/js/eds_results_article.js');
drupal_add_js(array('roblib_search_eds_articles' => array('search_url' => $search_url)), array('type' => 'setting'));
}
?>

Loading…
Cancel
Save