You are here

function finder::results in Finder 7.2

Finder results.

Create finder results output.

Return value

Themed output of finder results.

1 call to finder::results()
finder::render in includes/finder.inc
Finder render.

File

includes/finder.inc, line 848
finder.inc

Class

finder
An object to contain all of the data to generate a finder, plus the member functions to build the finder, and render the output.

Code

function results() {
  $results = array(
    '#prefix' => '<div class="finder-results-' . $this->name . '">',
    '#suffix' => '</div>',
  );
  if (($this->display != 'block' || $this->display == 'block' && !empty($this->ajax)) && (!$this
    ->setting('ajax_results_load') || !empty($this->ajax))) {
    $this->form_state = finder_form_state($this);
    module_invoke_all('finder_results', $this);
    if (!empty($this->form_state['finished']) || $this
      ->setting('show_results') == 'filter') {
      $keywords = array();
      $pager = $this
        ->setting('pager');
      foreach ($this->elements as $element) {
        if ($element->element_handler['type'] == 'form') {
          $keyword = array(
            NULL,
          );
          if (isset($this->form_state['values'][$element->id]) && !is_null($this->form_state['values'][$element->id])) {
            $keyword = (array) $this->form_state['values'][$element->id];
            if ($this
              ->esetting($element, 'delimit')) {

              // This enables escaped characters to work in delimiters.
              $delimiter = stripcslashes($this
                ->esetting($element, 'delimit'));
              foreach ($keyword as $k => $v) {
                unset($keyword[$k]);
                $exploded = explode($delimiter, $v);
                foreach ($exploded as $e) {
                  $keyword[] = trim($e);
                }
              }
            }
          }
          $keywords[$element->id] = $keyword;
        }
      }
      $redirect = $this
        ->setting('redirect');
      if (!empty($_GET['go']) || isset($this->form_state['clicked_button']) && $this->form_state['clicked_button']['#name'] == 'go' && $this->form_state['finished'] || $redirect == 'always') {
        $this->go = TRUE;
      }
      $this->find = array(
        'mode' => 'results',
        'keywords' => $keywords,
        'pager' => $pager,
      );
      $this
        ->find();
      if ($pager) {
        pager_default_initialize($this->view->query->pager->total_items, $pager);
      }
      if ($this
        ->setting('url') == 'disabled') {
        if ($pager && !isset($this->form_state['pager_token'])) {
          $token = drupal_get_token();
          $this->form_state['pager_token'] = $token;
          $_SESSION['finder'][$token] = $this->form_state;
        }
      }
      if (empty($this->ajax)) {
        if (!empty($this->go) && !empty($this->find['results']) || $redirect == 'best' && count($this->find['results']) === 1 && empty($_GET['page'])) {
          $this
            ->go();
        }
      }

      // Search module integration.
      if ($this
        ->setting('search') && empty($this->find['results']) && module_exists('search') && !empty($keywords)) {
        $keys = array();

        // @todo ability to exclude certain fields/elements from being included in the search keywords.
        foreach ($keywords as $finder_element_id => $finder_element_keywords) {
          foreach ((array) $finder_element_keywords as $keyword) {
            $keys[] = $keyword;
          }
        }
        $search_module_output = search_data(implode(' OR ', $keys), $this
          ->setting('search_tab'));
        if (!empty($search_module_output['#results'])) {
          $results['results'] = $search_module_output;
        }
      }

      // Results handling.
      if (empty($results['results']) && (!empty($this->find['results']) || $this
        ->setting('no_results') == 'default')) {
        if ($this
          ->setting('results_style') == 'custom') {

          // Custom themed results.
          $results['results'] = array(
            '#theme' => 'finder_results',
            '#finder' => $this,
          );
        }
        elseif ($this
          ->setting('results_style') == 'views') {

          // @todo: see if we can use a views_handler_area here to put in footer/header/empty.
          // Results from views module.
          $results['results']['#prefix'] = $this->find['results_prefix'];
          if (!$this
            ->setting('results_style_views_format')) {
            foreach ($this->find['results'] as $result) {
              $results['results'][]['#markup'] = $result->{$result->display_key};
            }
          }
          $results['results']['#suffix'] = $this->find['results_suffix'];
        }
        $results['pager'] = array(
          '#theme' => 'pager',
        );
      }
      elseif (empty($results['results']) && $this
        ->setting('no_results') == 'configured') {

        // Configured output.
        $variables = array(
          'finder' => $this,
          'keywords' => $keywords,
          'form_state' => $this->form_state,
        );
        $results['results']['#markup'] = finder_eval($this
          ->setting('no_results_configured'), $variables);
      }
    }

    // custom changes - undo separator encoding
    $sep = $this
      ->setting('url_delimiter');
    $url_empty_sep = $this
      ->setting('url_empty');
    if (isset($results['results'])) {
      $results['results']['#suffix'] = str_replace("%20", $url_empty_sep, str_replace(urlencode($url_empty_sep), $url_empty_sep, str_replace(urlencode($sep), $sep, $results['results']['#suffix'])));
    }
    $this->find['results_render'] = $results;
  }
  return $results;
}