function view::init_query

Do some common building initialization.

4 calls to view::init_query()
view::build in includes/view.inc
Build the query for the view.
view::build_title in includes/view.inc
Force the view to build a title.
view::export in includes/view.inc
Export a view as PHP code.
view::init_pager in includes/view.inc
Initialize the pager.

File

includes/view.inc, line 945

Class

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

Code

public function init_query() {
    if (!empty($this->query)) {
        $class = get_class($this->query);
        if ($class && $class != 'stdClass') {
            // Return if query is already initialized.
            return TRUE;
        }
    }
    // Create and initialize the query object.
    $views_data = views_fetch_data($this->base_table);
    $this->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
    if (!empty($views_data['table']['base']['database'])) {
        $this->base_database = $views_data['table']['base']['database'];
    }
    if (empty($this->display_handler)) {
        return FALSE;
    }
    // Load the options.
    $query_options = $this->display_handler
        ->get_option('query');
    // Create and initialize the query object.
    $plugin = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query';
    $this->query = views_get_plugin('query', $plugin);
    if (empty($this->query)) {
        return FALSE;
    }
    $this->query
        ->init($this->base_table, $this->base_field, $query_options['options']);
    return TRUE;
}