You are here

function ds_search_extra_variables in Display Suite 7

Same name and namespace in other branches
  1. 7.2 modules/ds_search/ds_search.module \ds_search_extra_variables()

Return the extra variables.

1 call to ds_search_extra_variables()
ds_build_shared_page_variables in modules/ds_search/ds_search.module
Build shared page variables.

File

modules/ds_search/ds_search.module, line 469
Display Suite search.

Code

function ds_search_extra_variables($arg_keys = NULL) {
  $type = variable_get('ds_search_variables', 'none');

  // Define the number of results being shown on a page.
  // We rely on the apache solr rows for now.
  $items_per_page = variable_get('apachesolr_rows', 10);

  // Get the current page.
  $current_page = isset($_REQUEST['page']) ? $_REQUEST['page'] + 1 : 1;

  // Get the total number of results from the $GLOBALS.
  $total = isset($GLOBALS['pager_total_items'][0]) ? $GLOBALS['pager_total_items'][0] : 0;

  // Perform calculation
  $start = $items_per_page * $current_page - ($items_per_page - 1);
  $end = $items_per_page * $current_page;
  if ($end > $total) {
    $end = $total;
  }

  // Get the search keys.
  $keys = empty($arg_keys) ? trim(ds_search_get_keys()) : $arg_keys;

  // Send the right extra variable.
  switch ($type) {
    case 'search_totals':
      return t('Total results: @total.', array(
        '@total' => $total,
      ));
      break;
    case 'search_totals_plus_keywords':
      return t('Your search for "<strong>@search</strong>" gave back @total results.', array(
        '@search' => $keys,
        '@total' => $total,
      ));
      break;
    case 'search_totals_from_to_end':
      return t('Displaying @start - @end of @total results.', array(
        '@start' => $start,
        '@end' => $end,
        '@total' => $total,
      ));
      break;
  }
}