From 366cea95007623ac6cbaed5ae708fdee67fb4799 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Thu, 11 Apr 2013 16:41:13 -0300 Subject: [PATCH] work on evergreen target --- css/roblib_search.base.css | 2 +- .../evergreen/css/roblib_search_evergreen.css | 12 ++++ targets/evergreen/js/evergreen_results.js | 34 +++++++++-- .../evergreen/roblib_search_evergreen.info | 2 +- .../evergreen/roblib_search_evergreen.module | 60 +++++++++++++++---- .../theme/roblib-search-evergreen.tpl.php | 2 +- 6 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 targets/evergreen/css/roblib_search_evergreen.css diff --git a/css/roblib_search.base.css b/css/roblib_search.base.css index 26576bd..16cdd77 100644 --- a/css/roblib_search.base.css +++ b/css/roblib_search.base.css @@ -11,7 +11,7 @@ border-bottom:1px #cecfcc dotted; } .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{ text-align: right; font-size: smaller; diff --git a/targets/evergreen/css/roblib_search_evergreen.css b/targets/evergreen/css/roblib_search_evergreen.css new file mode 100644 index 0000000..3fdf313 --- /dev/null +++ b/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; +} diff --git a/targets/evergreen/js/evergreen_results.js b/targets/evergreen/js/evergreen_results.js index 0a7ddf8..d71a153 100644 --- a/targets/evergreen/js/evergreen_results.js +++ b/targets/evergreen/js/evergreen_results.js @@ -1,23 +1,49 @@ Drupal.behaviors.roblib_search_evergreen = { attach: function(context, settings) { - $url = settings.roblib_search_evergreen.search_url; - jQuery.getJSON($url, function(data) { + url = settings.roblib_search_evergreen.search_url; + jQuery.getJSON(url, function(data) { var items = []; if(data.length < 1){ jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results'); } else { jQuery.each(data, function(key, val) { + items.push('
'); items.push('
'); - items.push(''+val.title+'
'); + if (typeof val.title !== 'undefined') { + items.push(''+val.title); + } + if (typeof val.subtitle !== 'undefined') { + items.push(' ' + val.subtitle); + } + items.push('
'); + if (typeof val.sor !== 'undefined') { + items.push('
' + val.sor +'
'); + } + if (typeof val.date !== 'undefined') { + items.push('
' + val.date + '
') + } + if(typeof val.holdings !== 'undefined'){ + items.push('
'); + jQuery.each(val.holdings, function(key2, val2){ + roblibEvergreenAddHoldings(val2, items); + }) + items.push('
') + } items.push(''); }); } - 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('See all ' + data.numberOfRecords + ' results'); }); } } +function roblibEvergreenAddHoldings(holdings, items){ + items.push('
' + holdings.call_number + ' ' + holdings.availability + '
'); + +} + diff --git a/targets/evergreen/roblib_search_evergreen.info b/targets/evergreen/roblib_search_evergreen.info index 1c5e9fb..426c6a7 100644 --- a/targets/evergreen/roblib_search_evergreen.info +++ b/targets/evergreen/roblib_search_evergreen.info @@ -5,4 +5,4 @@ description = implements the Roblib Search modules _roblib_search hook package = Roblib Search version = 7.x-dev core = 7.x -stylesheets[all][] = css/roblib_search_evergreen.base.css \ No newline at end of file +stylesheets[all][] = css/roblib_search_evergreen.css \ No newline at end of file diff --git a/targets/evergreen/roblib_search_evergreen.module b/targets/evergreen/roblib_search_evergreen.module index f5fb2af..4913248 100644 --- a/targets/evergreen/roblib_search_evergreen.module +++ b/targets/evergreen/roblib_search_evergreen.module @@ -80,7 +80,15 @@ function roblib_search_evergreen_config_form($form, &$form_state) { '#type' => 'textfield', '#title' => t('Evergreen detail suffix'), '#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, ); $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_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'); - $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); if ($results->code == '200') { - $output = roblib_search_evergreen_parse_results($results); + $output = roblib_search_evergreen_parse_results($results, $query); } else { $output = 'Error retrieving Evergreen results ' . $results->status_message; @@ -195,7 +206,7 @@ function roblib_search_evergreen_get_results($query) { * @return array $output * 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; if (!isset($xml)) { return 'no results found'; @@ -204,24 +215,51 @@ function roblib_search_evergreen_parse_results($results) { $output = array(); if ($sxml) { $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/marcxml:recordData/marcxml:record/marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]'); $index = 0; foreach ($records as $record) { - $record->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim'); - $title = $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]'); - $title = (string) $title[0]; - $id = $record->xpath('marcxml:datafield[@tag="901"]/marcxml:subfield[@code="c"]'); - $id = (string) $id[0]; - $output[$index]['title'] = $title; + $record->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim'); + roblib_search_evergreen_update_array($output, $index, 'title', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]')); + roblib_search_evergreen_update_array($output, $index, 'subtitle', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="b"]')); + roblib_search_evergreen_update_array($output, $index, 'sor', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="c"]')); + roblib_search_evergreen_update_array($output, $index, 'date', $record->xpath('marcxml:datafield[@tag="260"]/marcxml:subfield[@code="c"]')); + 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') . variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r=') - . (string) $id; + . (string)$id; } } 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(). * diff --git a/targets/evergreen/theme/roblib-search-evergreen.tpl.php b/targets/evergreen/theme/roblib-search-evergreen.tpl.php index a93ef59..ee8256a 100644 --- a/targets/evergreen/theme/roblib-search-evergreen.tpl.php +++ b/targets/evergreen/theme/roblib-search-evergreen.tpl.php @@ -21,4 +21,4 @@ -
Search all Results
\ No newline at end of file +
Search all Results
\ No newline at end of file