You are here

function ds_search_extra_variables in Display Suite 7.2

Same name and namespace in other branches
  1. 7 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 595
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 format_plural($total, 'One result', 'Total results: @total.', array(
        '@total' => $total,
      ));
      break;
    case 'search_totals_plus_keywords':
      return format_plural($total, 'Your search for "<strong>@search</strong>" gave back 1 result.', 'Your search for "<strong>@search</strong>" gave back @count results.', array(
        '@search' => $keys,
      ));
      break;
    case 'search_totals_from_to_end':
      return format_plural($total, 'Displaying @start - @end of 1 result.', 'Displaying @start - @end of @count results.', array(
        '@start' => $start,
        '@end' => $end,
      ));
      break;
  }
}