Browse Source

added per_page to cufts query started the eds target

2.x-ebsco
Paul Pound 12 years ago
parent
commit
cf734e328f
  1. 2
      targets/cufts/roblib_search_cufts.module
  2. 23
      targets/eds/js/eds_results.js
  3. 8
      targets/eds/roblib_search_eds.info
  4. 2
      targets/eds/roblib_search_eds.install
  5. 209
      targets/eds/roblib_search_eds.module
  6. 24
      targets/eds/theme/roblib-search-eds.tpl.php
  7. 25
      targets/eds/theme/theme.inc

2
targets/cufts/roblib_search_cufts.module

@ -175,7 +175,7 @@ function roblib_search_cufts_get_results($query = NULL) {
$url = variable_get('roblib_search_cufts_url', 'http://cufts2.lib.sfu.ca/CJDB/PCU/browse/show?');
$url_suffix = variable_get('roblib_search_cufts_search_suffix', 'browse_field=title&search_type=startswith&format=json&search_terms=');
$number_of_records = variable_get('roblib_search_cufts_num_results', '5');
$search_url = $url . $url_suffix . '"' . $query . '"' . '&submit=Search';
$search_url = $url . $url_suffix . '"' . $query . '"' . '&submit=Search&per_page='.$number_of_records;
$results = drupal_http_request($search_url);

23
targets/eds/js/eds_results.js

@ -0,0 +1,23 @@
Drupal.behaviors.roblib_search_cufts = {
attach: function(context, settings) {
$url = settings.roblib_search_eds.search_url;
jQuery.getJSON($url, function(data) {
var items = [];
if(data.length < 1){
jQuery('#' + 'roblib-search-content-eds').empty().append('No Results');
} else {
jQuery.each(data.journals, function(key, val) {
items.push('<div class ="roblib-search-row">');
items.push('<div class="roblib-title eds">');
items.push('<a href = "'+val.url+'">'+val.title+'</a></div>');
items.push('</div>');
});
}
jQuery('#' + 'roblib-search-content-eds').empty().append(items.join(''));
});
}
}

8
targets/eds/roblib_search_eds.info

@ -0,0 +1,8 @@
name = Roblib Search EDS
dependencies[] = roblib_search
configure = admin/roblib_search/eds_search
description = implements the Roblib Search modules _roblib_search hook
package = Roblib Search
version = 7.x-dev
core = 7.x
stylesheets[all][] = css/roblib_search_eds.base.css

2
targets/eds/roblib_search_eds.install

@ -0,0 +1,2 @@
<?php

209
targets/eds/roblib_search_eds.module

@ -0,0 +1,209 @@
<?php
/**
* @file
* Implementation of Roblib search for searching several targets.
*/
/**
* 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().
*/
function roblib_search_eds_menu() {
$items = array();
$items['admin/roblib_search/eds_search'] = array(
'title' => 'EDS search Target configuration',
'description' => 'Configuration for the Roblib evergreen search target',
'page callback' => 'drupal_get_form',
'page arguments' => array('roblib_search_eds_config_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items['roblib_search/eds/ajax/%'] = array(
'title' => 'eds ajax',
'page callback' => 'roblib_search_eds_ajax',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib eds'),
);
return $items;
}
function roblib_search_eds_config_form($form, &$form_state) {
$form['roblib_search_eds_url'] = array(
'#type' => 'textfield',
'#title' => t('EDS url'),
'#default_value' => variable_get('roblib_search_eds_url', 'http://eds2.lib.sfu.ca/CJDB/PCU/browse/show?'),
'#description' => t('The base EDS URL, for example http://eds2.lib.sfu.ca/CJDB/PCU/browse/show?'),
'#required' => TRUE,
);
$form['roblib_search_eds_search_suffix'] = array(
'#type' => 'textfield',
'#title' => t('EDS search suffix'),
'#default_value' => variable_get('roblib_search_eds_search_suffix', 'browse_field=title&search_type=startswith&format=json&search_terms='),
'#description' => t('The suffix will be appended to the base url for searches, for example browse_field=title&search_type=startswith&format=json&search_terms='),
'#required' => TRUE,
);
$form['roblib_search_eds_num_results'] = array(
'#type' => 'textfield',
'#title' => t('Number of results to return'),
'#default_value' => variable_get('roblib_search_eds_num_results', '5'),
'#description' => t('The number of results to display in the Bento box'),
'#required' => TRUE,
);
return system_settings_form($form);
}
/**
* Implements hook_permission().
*/
function roblib_search_eds_permission() {
return array(
'search roblib eds' => array(
'title' => t('Search the eds target'),
'description' => t('Search oblib eds target. This permission exposes the search blocks and allows you to see search results.'),
),
'administer roblib search eds' => array(
'title' => t('Administer Roblib Search EDS'),
'description' => t('Administer settings for the Roblib eds search client.'),
),
);
}
/**
* Implements hook_theme().
*/
function roblib_search_eds_theme() {
// set path
$path = drupal_get_path('module', 'roblib_search_eds');
$file = 'theme.inc';
return array(
// results page
'roblib_search_eds' => array(
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-eds',
'variables' => array('results' => NULL),
)
);
}
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, // default
);
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');
// 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
break;
}
return $block;
}
function roblib_search_eds_ajax($query) {
print roblib_search_eds_get_results($query);
exit();
}
/**
*
* @param string $query
* @return string
* json string
*/
function roblib_search_eds_get_results($query = NULL) {
drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
// Url parameters.
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
}
}
//http://eds2.lib.sfu.ca/CJDB/PCU/browse/show?browse_field=title&search_type=startswith&format=json&search_terms=dog&submit=Search
$url = variable_get('roblib_search_eds_url', 'http://eds2.lib.sfu.ca/CJDB/PCU/browse/show?');
$url_suffix = variable_get('roblib_search_eds_search_suffix', 'browse_field=title&search_type=startswith&format=json&search_terms=');
$number_of_records = variable_get('roblib_search_eds_num_results', '5');
$search_url = $url . $url_suffix . '"' . $query . '"' . '&submit=Search';
$results = drupal_http_request($search_url);
if ($results->code == '200') {
$output = $results->data;
}
else {
$output = $results->status_message;
}
return $output;
}
/**
* Implements hook_help().
*
* @param type $path
* @param type $arg
* @return type
*/
function roblib_search_eds_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search_eds':
return t(
'<p>
provides a target for the Roblib search module. This target uses javascript
to render the results.
</p>'
);
}
}

24
targets/eds/theme/roblib-search-eds.tpl.php

@ -0,0 +1,24 @@
<?php
/**
* @file islandora-solr-wrapper.tpl.php
* Islandora solr search results wrapper template
*
* Variables available:
* - $variables: all array elements of $variables can be used as a variable. e.g. $base_url equals $variables['base_url']
* - $base_url: The base url of the current website. eg: http://example.com .
* - $user: The user object.
*
*
* - $results: Rendered search results (primary profile)
*
*
* @see template_preprocess_roblib_search_wrapper()
*/
?>
<div class ="roblib-search-content eds" id="roblib-search-content-eds">
<img src="<?php print $spinner_path; ?>"/>
</div>
<div class ="roblib-search-more">Search all EDS</div>

25
targets/eds/theme/theme.inc

@ -0,0 +1,25 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
function roblib_search_eds_preprocess_roblib_search_eds(&$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/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'));
}
?>
Loading…
Cancel
Save