Browse Source

work on evergreen target

2.x-ebsco
Paul Pound 12 years ago
parent
commit
366cea9500
  1. 2
      css/roblib_search.base.css
  2. 12
      targets/evergreen/css/roblib_search_evergreen.css
  3. 34
      targets/evergreen/js/evergreen_results.js
  4. 2
      targets/evergreen/roblib_search_evergreen.info
  5. 56
      targets/evergreen/roblib_search_evergreen.module
  6. 2
      targets/evergreen/theme/roblib-search-evergreen.tpl.php

2
css/roblib_search.base.css

@ -11,7 +11,7 @@
border-bottom:1px #cecfcc dotted; border-bottom:1px #cecfcc dotted;
} }
.panels-ipe-portlet-wrapper { .panels-ipe-portlet-wrapper {
border-left:1px solid #cecfcc; border-right:1px solid #cecfcc; line-height: 2em; margin-bottom:10px; border-bottom:1px solid #cecfcc; border-left:1px solid #cecfcc; border-right:1px solid #cecfcc; line-height: 1.5em; margin-bottom:10px; border-bottom:1px solid #cecfcc;
} }
.roblib-search-more{ .roblib-search-more{
text-align: right; font-size: smaller; text-align: right; font-size: smaller;

12
targets/evergreen/css/roblib_search_evergreen.css

@ -0,0 +1,12 @@
/*
Document : roblib_search_evergreen
Created on : Apr 11, 2013, 2:27:50 PM
Author : ppound
Description:
Purpose of the stylesheet follows.
*/
.evergreen-sor, .evergreen-date, .evergreen-holdings-item{
padding-left: 10px; font-size: smaller;
}

34
targets/evergreen/js/evergreen_results.js

@ -1,23 +1,49 @@
Drupal.behaviors.roblib_search_evergreen = { Drupal.behaviors.roblib_search_evergreen = {
attach: function(context, settings) { attach: function(context, settings) {
$url = settings.roblib_search_evergreen.search_url; url = settings.roblib_search_evergreen.search_url;
jQuery.getJSON($url, function(data) { jQuery.getJSON(url, function(data) {
var items = []; var items = [];
if(data.length < 1){ if(data.length < 1){
jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results'); jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results');
} else { } else {
jQuery.each(data, function(key, val) { jQuery.each(data, function(key, val) {
items.push('<div class ="roblib-search-row">'); items.push('<div class ="roblib-search-row">');
items.push('<div class="roblib-title evergreen">'); items.push('<div class="roblib-title evergreen">');
items.push('<a href = "'+val.url+'">'+val.title+'</a></div>'); if (typeof val.title !== 'undefined') {
items.push('<a href = "'+val.url+'">'+val.title);
}
if (typeof val.subtitle !== 'undefined') {
items.push(' ' + val.subtitle);
}
items.push('</a></div>');
if (typeof val.sor !== 'undefined') {
items.push('<div class="evergreen-sor">' + val.sor +'</div>');
}
if (typeof val.date !== 'undefined') {
items.push('<div class="evergreen-date">' + val.date + '</div>')
}
if(typeof val.holdings !== 'undefined'){
items.push('<div class="evergreen-holdings">');
jQuery.each(val.holdings, function(key2, val2){
roblibEvergreenAddHoldings(val2, items);
})
items.push('</div>')
}
items.push('</div>'); items.push('</div>');
}); });
} }
jQuery('#' + 'roblib-search-content-evergreen').empty().append(items.join('')); jQuery('#roblib-search-content-evergreen').empty().append(items.join(''));
jQuery('#roblib-search-evergreen-more').empty().append('<a href = "' + data.catalogBaseSearchUrl + '">See all ' + data.numberOfRecords + ' results</a>');
}); });
} }
} }
function roblibEvergreenAddHoldings(holdings, items){
items.push('<div class="evergreen-holdings-item">' + holdings.call_number + ' ' + holdings.availability + '</div>');
}

2
targets/evergreen/roblib_search_evergreen.info

@ -5,4 +5,4 @@ description = implements the Roblib Search modules _roblib_search hook
package = Roblib Search package = Roblib Search
version = 7.x-dev version = 7.x-dev
core = 7.x core = 7.x
stylesheets[all][] = css/roblib_search_evergreen.base.css stylesheets[all][] = css/roblib_search_evergreen.css

56
targets/evergreen/roblib_search_evergreen.module

@ -80,7 +80,15 @@ function roblib_search_evergreen_config_form($form, &$form_state) {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Evergreen detail suffix'), '#title' => t('Evergreen detail suffix'),
'#default_value' => variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r='), '#default_value' => variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r='),
'#description' => t('The suffix will be appended to the base url when creating links to the Evergreen detail page, for example /opac/en-CA/skin/default/xml/rdetail.xml?r='), '#description' => t('The suffix will be appended to the base url when creating links to the Evergreen detail page, for example, /opac/en-CA/skin/default/xml/rdetail.xml?r='),
'#required' => TRUE,
);
//http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t=
$form['roblib_search_evergreen_catalog_base_search_url'] = array(
'#type' => 'textfield',
'#title' => t('Evergreen catalog base search url'),
'#default_value' => variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='),
'#description' => t('The Catalog base url so we can repeat the search in the catalog, for example, http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='),
'#required' => TRUE, '#required' => TRUE,
); );
$form['roblib_search_evergreen_num_results'] = array( $form['roblib_search_evergreen_num_results'] = array(
@ -176,10 +184,13 @@ function roblib_search_evergreen_get_results($query) {
$url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52'); $url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52');
$url_suffix = variable_get('roblib_search_evergreen_search_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query='); $url_suffix = variable_get('roblib_search_evergreen_search_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query=');
$number_of_records = variable_get('roblib_search_evergreen_num_results', '5'); $number_of_records = variable_get('roblib_search_evergreen_num_results', '5');
$search_url = $url . $url_suffix . '"' . urlencode($query) . '"' . '&maximumRecords=' . $number_of_records; $query = str_replace(' ', '%20AND%20',$query);//hack until the library decides if we want phrase or individual words
$search_url = $url . $url_suffix . $query . '&maximumRecords=' . $number_of_records;
drupal_add_js(array('roblib_search_evergreen' => array('catalog_url' => $catalog_base_search_url)), array('type' => 'setting'));
$results = drupal_http_request($search_url); $results = drupal_http_request($search_url);
if ($results->code == '200') { if ($results->code == '200') {
$output = roblib_search_evergreen_parse_results($results); $output = roblib_search_evergreen_parse_results($results, $query);
} }
else { else {
$output = 'Error retrieving Evergreen results ' . $results->status_message; $output = 'Error retrieving Evergreen results ' . $results->status_message;
@ -195,7 +206,7 @@ function roblib_search_evergreen_get_results($query) {
* @return array $output * @return array $output
* information we want from the xml stored in an array * information we want from the xml stored in an array
*/ */
function roblib_search_evergreen_parse_results($results) { function roblib_search_evergreen_parse_results($results, $query) {
$xml = $results->data; $xml = $results->data;
if (!isset($xml)) { if (!isset($xml)) {
return 'no results found'; return 'no results found';
@ -204,16 +215,25 @@ function roblib_search_evergreen_parse_results($results) {
$output = array(); $output = array();
if ($sxml) { if ($sxml) {
$sxml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim'); $sxml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
$sxml->registerXPathNamespace('srw', 'http://www.loc.gov/zing/srw/');
$number_of_records = $sxml->xpath('//srw:numberOfRecords');
$output['numberOfRecords'] = (string)$number_of_records[0];
$catalog_base_search_url = variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t=');
$catalog_base_search_url .= $query;
$output['catalogBaseSearchUrl'] = $catalog_base_search_url;
$records = $sxml->xpath('//marcxml:record'); $records = $sxml->xpath('//marcxml:record');
//$records = $sxml->xpath('//marcxml:record/marcxml:recordData/marcxml:record/marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]'); //$records = $sxml->xpath('//marcxml:record/marcxml:recordData/marcxml:record/marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]');
$index = 0; $index = 0;
foreach ($records as $record) { foreach ($records as $record) {
$record->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim'); $record->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
$title = $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]'); roblib_search_evergreen_update_array($output, $index, 'title', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]'));
$title = (string) $title[0]; roblib_search_evergreen_update_array($output, $index, 'subtitle', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="b"]'));
$id = $record->xpath('marcxml:datafield[@tag="901"]/marcxml:subfield[@code="c"]'); roblib_search_evergreen_update_array($output, $index, 'sor', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="c"]'));
$id = (string) $id[0]; roblib_search_evergreen_update_array($output, $index, 'date', $record->xpath('marcxml:datafield[@tag="260"]/marcxml:subfield[@code="c"]'));
$output[$index]['title'] = $title; roblib_search_evergreen_update_array($output, $index, 'id', $record->xpath('marcxml:datafield[@tag="901"]/marcxml:subfield[@code="c"]'));
roblib_search_evergreen_holdings($output, $index, $record->xpath('marcxml:datafield[@tag="852"]'));
$id = $output[$index]['id'];
$output[$index++]['url'] = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52') $output[$index++]['url'] = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52')
. variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r=') . variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r=')
. (string)$id; . (string)$id;
@ -222,6 +242,24 @@ function roblib_search_evergreen_parse_results($results) {
return $output; return $output;
} }
function roblib_search_evergreen_holdings(&$arr, $index, $xpath_result){
$holding_index = 0;
foreach($xpath_result as $xml){
$xml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
$call_number = $xml->xpath('marcxml:subfield[@code="c"]');
$arr[$index]['holdings'][$holding_index]['call_number'] = (string)$call_number[0];
$availability = $xml->xpath('marcxml:subfield[@code="n"]');
$arr[$index]['holdings'][$holding_index++]['availability'] = (string)$availability[0];
}
}
function roblib_search_evergreen_update_array(&$arr, $index, $key, $xpath_result){
if(!empty($xpath_result)){
$val = (string)$xpath_result[0];
$arr[$index][$key] = $val;
}
}
/** /**
* Implements hook_help(). * Implements hook_help().
* *

2
targets/evergreen/theme/roblib-search-evergreen.tpl.php

@ -21,4 +21,4 @@
<img src="<?php print $spinner_path; ?>"/> <img src="<?php print $spinner_path; ?>"/>
</div> </div>
<div class ="roblib-search-more">Search all Results</div> <div class ="roblib-search-more" id="roblib-search-evergreen-more">Search all Results</div>
Loading…
Cancel
Save