You are here

function finder::views_find in Finder 7.2

Finder views find.

A subfunction of find() which deals specifically with the Views module.

1 call to finder::views_find()
finder::find in includes/finder.inc
Finder find.

File

includes/finder.inc, line 713
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 views_find() {
  $this->find['field_info'] = array();
  $this->find['groups'] = array();
  $mode =& $this->find['mode'];
  $pager =& $this->find['pager'];
  $element =& $this->find['element'];
  $reset =& $this->find['reset'];

  // Some defaults.
  $mode = $mode ? $mode : 'choices';
  $pager = $pager ? $pager : 0;
  $element = $element ? $element : NULL;
  $reset = $reset ? $reset : FALSE;
  if ($view = views_get_view($this->views_view)) {
    $this->view = $view;
    $view_args = array();
    $display = null;
    if ($mode == 'choices' || $mode == 'results' && $this
      ->setting('results_style') == 'custom' && !$this
      ->setting('custom_results_style_render')) {
      $display = $view
        ->add_display('finder');

      // Change the display options based on 'query display' setting.
      $custom_display = null;
      if ($mode == 'results') {
        $custom_display = $this->views_display;
      }
      elseif ($mode == 'choices') {
        $custom_display = $this
          ->esetting($element, 'display');
        if (!$custom_display) {
          $custom_display = $this->views_display;
        }
      }
      $view->display[$display]->display_options = $view->display[$custom_display]->display_options;
    }
    elseif ($mode == 'results') {
      $display = $view
        ->add_display($this->views_display);
      $view->finder_results_display = TRUE;
    }

    // Activate the display
    $view
      ->set_display($display);
    if ($mode != 'results' || !$this
      ->setting('results_style_views_format')) {
      $view->display_handler
        ->set_option('style_plugin', 'finder');
    }
    if ($mode == 'choices' || $mode == 'results' && $this
      ->setting('results_style') == 'custom' && !$this
      ->setting('custom_results_style_render')) {
      $view->display_handler
        ->set_option('row_plugin', 'fields');
    }
    $view->display_handler
      ->set_option('finder', $this);

    // Limit result set size.
    if (!empty($pager)) {
      $view
        ->set_items_per_page($pager);
      $view->display_handler
        ->set_option('use_pager', TRUE);
      $pager_element = $mode == 'results' ? 0 : 'finder_choices_' . $element->id;
      $view->display_handler
        ->set_option('pager_element', $pager_element);
      if (!empty($_GET['page'])) {
        $view
          ->set_offset($_GET['page'] * $pager);
      }
      $view->get_total_rows = true;

      // Added because of #1648984.
      $pager_option = $view->display_handler
        ->get_option('pager');
      if ($pager_option['type'] == 'none') {
        $pager_option['type'] = 'some';
        $view->display_handler
          ->set_option('pager', $pager_option);
      }
    }
    if ($mode == 'results') {
      $view_args = $this
        ->arguments();

      // Limit result for redirect.
      if (isset($this->go) && $this->go) {
        $view->display_handler
          ->set_option('use_pager', TRUE);
        $view->display_handler
          ->set_option('items_per_page', 1);
        $view->display_handler
          ->set_option('pager_element', 0);

        // Added because of #1648984.
        $pager_option = $view->display_handler
          ->get_option('pager');
        if ($pager_option['type'] == 'none' && $pager) {
          $pager_option['type'] = 'some';
          $view->display_handler
            ->set_option('pager', $pager_option);
        }
      }
    }
    elseif ($mode == 'choices') {
      $view_args = $this
        ->element_arguments($element);
      $view->display_handler
        ->set_option('distinct', TRUE);
    }

    // Make sure the query is not cached
    // @todo: what happens is we do let it get cached?
    $view->is_cacheable = FALSE;

    // Removed because of issue #1345930.

    //$view->build($display);
    $view->display[$display]->handler = $view->display_handler;
    $this->find['results'] = $view
      ->execute_display($display, $view_args);
    if ($mode == 'results' && ($this
      ->setting('results_style') == 'views' || $this
      ->setting('results_style') == 'custom' && $this
      ->setting('custom_results_style_render'))) {
      if (is_array($this->find['results']) && isset($this->find['results']['content'])) {
        $this->find['results'] = $this->find['results']['content'];
      }
      $wrapper = explode('[%FINDER_RESULTS%]', $this->find['results']);
      $this->find['results_prefix'] = isset($wrapper[0]) ? $wrapper[0] : '';
      $this->find['results_suffix'] = isset($wrapper[1]) ? $wrapper[1] : '';
      $this->find['results'] = $view->result;
    }
  }
}