You are here

function apachesolr_search_load_all_search_pages in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr_search.module \apachesolr_search_load_all_search_pages()
  2. 7 apachesolr_search.module \apachesolr_search_load_all_search_pages()

Return all the saved search pages

Return value

array $search_pages Array of all search pages

6 calls to apachesolr_search_load_all_search_pages()
apachesolr_search_form_search_block_form_alter in ./apachesolr_search.module
Implements hook_form_[form_id]_alter().
apachesolr_search_menu_alter in ./apachesolr_search.module
apachesolr_search_pages_config_form in ./apachesolr_search.admin.inc
apachesolr_search_page_clone in ./apachesolr_search.module
Function that clones a search page
apachesolr_search_page_list_pages in ./apachesolr_search.admin.inc
Listing of all the search pages

... See full list

File

./apachesolr_search.module, line 605
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_load_all_search_pages($reset = FALSE) {
  static $search_pages = array();
  if ($reset) {
    $search_pages = array();
    if (module_exists('ctools')) {
      ctools_include('export');
      ctools_export_load_object_reset('apachesolr_search_page');
    }
  }
  if (!empty($search_pages)) {
    return $search_pages;
  }

  // Get all search_pages and their id
  if (db_table_exists('apachesolr_search_page')) {

    // If ctools module is enabled, add search pages from code, e.g. from a
    // feature module.
    if (module_exists('ctools')) {
      ctools_include('export');
      $defaults = ctools_export_load_object('apachesolr_search_page', 'all');
      foreach ($defaults as $page_id => $default) {
        if (!isset($search_pages[$page_id])) {
          $search_pages[$page_id] = (array) $default;
        }
      }
    }

    // Get all search_pages and their id
    $search_pages_db = array();
    $search_pages_db_results = db_query('SELECT * FROM {apachesolr_search_page}');
    while ($search_pages_db_result = db_fetch_array($search_pages_db_results)) {
      $search_pages_db[$search_pages_db_result['page_id']] = $search_pages_db_result;
    }
    $search_pages = $search_pages + $search_pages_db;

    // Ensure that the core search page uses the default environment. In some
    // instances, for example when unit testing, this search page isn't defined.
    if (isset($search_pages['core_search'])) {
      $search_pages['core_search']['env_id'] = apachesolr_default_environment();
    }

    // convert settings to an array
    foreach ($search_pages as $id => $search_page) {
      if (is_string($search_pages[$id]['settings'])) {
        $search_pages[$id]['settings'] = unserialize($search_pages[$id]['settings']);
      }
    }
  }
  return $search_pages;
}