Browse Source

some code formating and make blocks disapper if there are no results

2.x-ebsco
Paul Pound 11 years ago
parent
commit
2b1ba7eadc
  1. 64
      roblib_search.module
  2. 3
      targets/cufts/js/cufts_results.js
  3. 3
      targets/eds/js/eds_results.js
  4. 3
      targets/evergreen/js/evergreen_results.js
  5. 4
      targets/solr_site/js/solr_site_results.js
  6. 45
      targets/solr_site/roblib_search_solr_site.module

64
roblib_search.module

@ -6,31 +6,6 @@
*/ */
/**
* Implements hook_boot().
* @global type $conf
*/
function roblib_search_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(). * Implements hook_menu().
*/ */
@ -42,7 +17,6 @@ function roblib_search_menu() {
'access arguments' => array('administer site configuration'), 'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM, 'type' => MENU_NORMAL_ITEM,
); );
$items['admin/roblib_search/configure'] = array( $items['admin/roblib_search/configure'] = array(
'title' => 'Global Configuration', 'title' => 'Global Configuration',
'description' => 'Configure global Roblib search settings.', 'description' => 'Configure global Roblib search settings.',
@ -51,15 +25,12 @@ function roblib_search_menu() {
'page arguments' => array('roblib_search_config_form'), 'page arguments' => array('roblib_search_config_form'),
'type' => MENU_NORMAL_ITEM, 'type' => MENU_NORMAL_ITEM,
); );
return $items; return $items;
} }
function roblib_search_config_form($form, &$form_state) { function roblib_search_config_form($form, &$form_state) {
//variable_get('roblib_search_panel_page','/roblib/panel');
$form['roblib_search_panel_page'] = array( $form['roblib_search_panel_page'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Path to the roblib search panel page'), '#title' => t('Path to the roblib search panel page'),
@ -68,7 +39,6 @@ function roblib_search_config_form($form, &$form_state) {
'#required' => TRUE, '#required' => TRUE,
); );
return system_settings_form($form); return system_settings_form($form);
} }
@ -105,14 +75,14 @@ function roblib_search_block_info() {
// info: The name of the block. // info: The name of the block.
'info' => t('Roblib Global Search Form'), 'info' => t('Roblib Global Search Form'),
// Block caching options (per role, per user, etc.) // Block caching options (per role, per user, etc.)
'cache' => DRUPAL_CACHE_PER_ROLE, // default // Default.
'cache' => DRUPAL_CACHE_PER_ROLE,
); );
return $blocks; return $blocks;
} }
function roblib_search_block_view($delta = '') { function roblib_search_block_view($delta = '') {
//The $delta parameter tells us which block is being requested.
switch ($delta) { switch ($delta) {
case 'roblib_search_form': case 'roblib_search_form':
// The subject is displayed at the top of the block. Note that it // The subject is displayed at the top of the block. Note that it
@ -128,25 +98,26 @@ function roblib_search_block_view($delta = '') {
} }
/** /**
* Roblib search simple search form submit * Roblib search simple search form submit.
* *
* @param type $form * @param array $form
* @param array $form_state * @param array $form_state
*
*/ */
function roblib_search_simple_form_submit($form, &$form_state) { function roblib_search_simple_form_submit($form, &$form_state) {
global $base_url; global $base_url;
$form_state['rebuild'] = TRUE; $form_state['rebuild'] = TRUE;
$search_string = $form_state['values']['roblib_search_simple_search_query']; $search_string = $form_state['values']['roblib_search_simple_search_query'];
$redirect_url = variable_get('roblib_search_panel_page','roblib/panel'); $redirect_url = variable_get('roblib_search_panel_page', 'roblib/panel');
$redirect_url = $base_url. '/' . $redirect_url; $redirect_url = $base_url . '/' . $redirect_url;
drupal_goto($redirect_url, array('query' => array('roblib_query' => $search_string))); drupal_goto($redirect_url, array('query' => array('roblib_query' => $search_string)));
} }
/** /**
* Roblib search simple search form * Roblib search simple search form
* *
* @param type $form * @param array $form
* @param type $form_state * @param array $form_state
* @return array * @return array
*/ */
function roblib_search_simple_form($form, &$form_state) { function roblib_search_simple_form($form, &$form_state) {
@ -154,16 +125,17 @@ function roblib_search_simple_form($form, &$form_state) {
$query = $_GET['roblib_query']; $query = $_GET['roblib_query'];
} }
else { else {
$query = ''; $query = '';
} }
$form['simple'] = array( $form['simple'] = array(
'#type' => 'container', '#type' => 'container',
'#attributes' => array( '#attributes' => array(
'class' => array( 'class' => array(
'container-inline') 'container-inline'
) )
); )
);
$form['simple']["roblib_search_simple_search_query"] = array( $form['simple']["roblib_search_simple_search_query"] = array(
'#size' => '15', '#size' => '15',
'#type' => 'textfield', '#type' => 'textfield',
@ -188,11 +160,11 @@ function roblib_search_help($path, $arg) {
switch ($path) { switch ($path) {
case 'admin/help#roblib_search': case 'admin/help#roblib_search':
return t( return t(
'<p> '<p>
The Roblib Search is a module to allow searching across multiple targets. The Roblib Search is a module to allow searching across multiple targets.
This module does not know how to retrieve results but fires hooks that other This module does not know how to retrieve results but fires hooks that other
modules can implement to gather and display results. modules can implement to gather and display results.
</p>' </p>'
); );
} }
} }

3
targets/cufts/js/cufts_results.js

@ -3,8 +3,9 @@ Drupal.behaviors.roblib_search_cufts = {
url = settings.roblib_search_cufts.search_url; url = settings.roblib_search_cufts.search_url;
jQuery.getJSON(url, function(data) { jQuery.getJSON(url, function(data) {
var items = []; var items = [];
if (data.length < 1) { if (data.journals.length < 1) {
jQuery('#' + 'roblib-search-content-cufts').empty().append('No Results'); jQuery('#' + 'roblib-search-content-cufts').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-cufts-roblib-search-cufts-results').hide();
} else { } else {
jQuery.each(data.journals, function(key, val) { jQuery.each(data.journals, function(key, val) {
var item_str = '<div class ="roblib-search-row">'; var item_str = '<div class ="roblib-search-row">';

3
targets/eds/js/eds_results.js

@ -3,8 +3,9 @@ Drupal.behaviors.roblib_search_eds = {
$url = settings.roblib_search_eds.search_url; $url = settings.roblib_search_eds.search_url;
jQuery.getJSON($url, function(data) { jQuery.getJSON($url, function(data) {
var items = []; var items = [];
if(data.length < 1){ if(data.records.length < 1){
jQuery('#' + 'roblib-search-content-eds').empty().append('No Results'); jQuery('#' + 'roblib-search-content-eds').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-eds-roblib-search-eds-results').hide();
} else { } else {
jQuery.each(data.records, function(key, val) { jQuery.each(data.records, function(key, val) {

3
targets/evergreen/js/evergreen_results.js

@ -3,8 +3,9 @@ Drupal.behaviors.roblib_search_evergreen = {
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.numberOfRecords < 1){
jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results'); jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results');
jQuery('.pane-roblib-search-evergreen-roblib-search-evergreen-results').hide();
} else { } else {
jQuery.each(data, function(key, val) { jQuery.each(data, function(key, val) {

4
targets/solr_site/js/solr_site_results.js

@ -3,8 +3,9 @@ Drupal.behaviors.roblib_search_solr_site = {
url = settings.roblib_search_solr_site.search_url; url = settings.roblib_search_solr_site.search_url;
jQuery.getJSON(url, function(data) { jQuery.getJSON(url, function(data) {
var items = []; var items = [];
if (data.length < 1) { if (data.response.docs.length < 1) {
jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results'); jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-results').hide();
} else { } else {
jQuery.each(data.response.docs, function(key, val) { jQuery.each(data.response.docs, function(key, val) {
items.push('<div class ="roblib-search-row">\n\ items.push('<div class ="roblib-search-row">\n\
@ -14,7 +15,6 @@ Drupal.behaviors.roblib_search_solr_site = {
var number = parseInt(data.rows); var number = parseInt(data.rows);
jQuery('#' + 'roblib-search-content-solr-site').empty(); jQuery('#' + 'roblib-search-content-solr-site').empty();
items = showMoreItems(items, number); items = showMoreItems(items, number);
} }
}); });
} }

45
targets/solr_site/roblib_search_solr_site.module

@ -5,30 +5,6 @@
* Implementation of Roblib search for searching several targets. * Implementation of Roblib search for searching several targets.
*/ */
/**
* Implements hook_boot().
* @global type $conf
*/
function roblib_search_solr_site_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(). * Implements hook_menu().
@ -69,7 +45,7 @@ function roblib_search_solr_site_config_form($form, &$form_state) {
'#description' => t('The base Solr URL, for example http://localhost:8983/solr'), '#description' => t('The base Solr URL, for example http://localhost:8983/solr'),
'#required' => TRUE, '#required' => TRUE,
); );
$form['roblib_search_solr_site_num_results'] = array( $form['roblib_search_solr_site_num_results'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Number of results to return'), '#title' => t('Number of results to return'),
'#default_value' => variable_get('roblib_search_solr_site_num_results', '5'), '#default_value' => variable_get('roblib_search_solr_site_num_results', '5'),
@ -163,26 +139,25 @@ function roblib_search_solr_site_get_results($query) {
'wt' => 'json', 'wt' => 'json',
'q' => $query, 'q' => $query,
); );
$url = url($solr_url.'/select', array('query' => $data)); $url = url($solr_url . '/select', array('query' => $data));
$results = drupal_http_request($url); $results = drupal_http_request($url);
$temp = substr($results->data, 1); if($results->code != '200'){
$out = '{"rows":"'.$num_results.'",'.$temp; return "";
return $out; }
$temp = substr($results->data, 1);
//$out = '{"rows":"' . $num_results . '",' . $results->data;
return $results->data;
} }
/** /**
* Implements hook_help(). * Implements hook_help().
*
* @param type $path
* @param type $arg
* @return type
*/ */
function roblib_search_solr_site_help($path, $arg) { function roblib_search_solr_site_help($path, $arg) {
switch ($path) { switch ($path) {
case 'admin/help#roblib_search_solr_site': case 'admin/help#roblib_search_solr_site':
return t( return t(
'<p> '<p>
provides a target for the Roblib search module provides a target for the Roblib search module
</p>' </p>'
); );
} }

Loading…
Cancel
Save