function view::execute

Same name in other branches
  1. 6.x-3.x includes/view.inc \view::execute()

Execute the view's query.

Parameters

string $display_id: The machine name of the display, which should be executed.

Return value

bool Return whether the executing was successful, for example an argument could stop the process.

1 call to view::execute()
view::render in includes/view.inc
Render this view for a certain display.

File

includes/view.inc, line 1184

Class

view
An object to contain all of the data to generate a view.

Code

public function execute($display_id = NULL) {
    if (empty($this->built)) {
        if (!$this->build($display_id)) {
            return FALSE;
        }
    }
    if (!empty($this->executed)) {
        return TRUE;
    }
    // Don't allow to use deactivated displays, but display them on the live
    // preview.
    if (!$this->display[$this->current_display]->handler
        ->get_option('enabled') && empty($this->live_preview)) {
        $this->build_info['fail'] = TRUE;
        return FALSE;
    }
    // Let modules modify the view just prior to executing it.
    foreach (module_implements('views_pre_execute') as $module) {
        $function = $module . '_views_pre_execute';
        $function($this);
    }
    // Check for already-cached results.
    if (!empty($this->live_preview)) {
        $cache = FALSE;
    }
    elseif (views_view_has_form_elements($this) && isset($_POST['form_id']) && $_POST['form_id'] == views_form_id($this)) {
        $cache = FALSE;
    }
    else {
        $cache = $this->display_handler
            ->get_plugin('cache');
    }
    if ($cache && $cache->cache_get('results')) {
        if ($this->query->pager
            ->use_pager() || !empty($this->get_total_rows)) {
            $this->query->pager->total_items = $this->total_rows;
            $this->query->pager
                ->update_page_info();
        }
        vpr('Used cached results');
    }
    else {
        $this->query
            ->execute($this);
        // Enforce the array key rule as documented in
        // views_plugin_query::execute().
        $this->result = array_values($this->result);
        $this->_post_execute();
        if ($cache) {
            $cache->cache_set('results');
        }
    }
    // Let modules modify the view just after executing it.
    foreach (module_implements('views_post_execute') as $module) {
        $function = $module . '_views_post_execute';
        $function($this);
    }
    $this->executed = TRUE;
}