You are here

function apachesolr_multisitesearch_get_site_options in Apache Solr Multisite Search 7

Return an array of multisite search sites keyed by hash.

2 calls to apachesolr_multisitesearch_get_site_options()
apachesolr_multisitesearch_form_apachesolr_environment_edit_form_alter in ./apachesolr_multisitesearch.module
Implements hook_form_FORM_ID_alter().
apachesolr_multisitesearch_settings in ./apachesolr_multisitesearch.admin.inc
Creates the form that allows the user to select which facets will be enabled.

File

./apachesolr_multisitesearch.module, line 121
Provides a multi-site search implementation for use with the Apache Solr module

Code

function apachesolr_multisitesearch_get_site_options() {
  $options =& drupal_static(__FUNCTION__);
  if (!isset($options)) {
    $site_hash = apachesolr_site_hash();
    module_load_include('inc', 'apachesolr_multisitesearch', 'apachesolr_multisitesearch.index');
    $metadata = variable_get('apachesolr_multisitesearch_metadata', array());
    $hashes = apachesolr_multisitesearch_get_site_hashes();
    $options = array();
    foreach ($hashes as $hash => $count) {
      if ($hash == $site_hash) {
        $options[$hash] = t('This site (!site, !count documents)', array(
          '!site' => variable_get('site_name', 'Drupal'),
          '!count' => $count,
        ));
      }
      elseif (!empty($metadata[$hash])) {
        $options[$hash] = $metadata[$hash]['site'] . ' ' . t('(!count documents)', array(
          '!count' => $count,
        ));
      }
      else {
        $options[$hash] = $hash . ' ' . t('(!count documents)', array(
          '!count' => $count,
        ));
      }
    }

    // This site should always be in the list of options.
    if (!isset($options[$site_hash])) {
      $options[$site_hash] = t('This site (!site)', array(
        '!site' => variable_get('site_name', 'Drupal'),
      ));
    }
  }
  return $options;
}