Newer
Older
The Great Git Migration
committed
<?php
The Great Git Migration
committed
/**
* @file
* @defgroup views_objects Objects that represent a View or part of a view
The Great Git Migration
committed
* @{
* These objects are the core of Views do the bulk of the direction and
* storing of data. All database activity is in these objects.
*/
/**
Damien McKenna
committed
* An object to contain all of the data to generate a view.
*
* Also includes the member functions to build the view query, execute the
* query and render the output.
The Great Git Migration
committed
*/
class view extends views_db_object {
Damien McKenna
committed
/**
*
*/
public $db_table = 'views_view';
/**
*
*/
public $base_table = 'node';
/**
*
*/
public $base_field = 'nid';
The Great Git Migration
committed
Daniel Wehner
committed
/**
* The name of the view.
*
* @var string
*/
Damien McKenna
committed
public $name = "";
Daniel Wehner
committed
/**
* The id of the view, which is used only for views in the database.
*
* @var number
*/
Damien McKenna
committed
public $vid;
/**
* The description of the view, which is used only in the interface.
*
* @var string
*/
Damien McKenna
committed
public $description;
/**
* The "tags" of a view.
* The tags are stored as a single string, though it is used as multiple tags
* for example in the views overview.
*
* @var string
*/
Damien McKenna
committed
public $tag;
/**
* The human readable name of the view.
*
* @var string
*/
Damien McKenna
committed
public $human_name;
/**
* The core version the view was created for.
Damien McKenna
committed
*
* @var int
*/
Damien McKenna
committed
public $core;
/**
* The views-api version this view was created by.
*
* Some examples of the variable are 3.0 or 3.0-alpha1
*
* @var string
*/
Damien McKenna
committed
public $api_version;
/**
* Is the view disabled.
*
Damien McKenna
committed
* This value is used for exported view, to provide some default views which
* aren't enabled.
*
* @var bool
*/
Damien McKenna
committed
public $disabled;
/**
* State variable.
*/
public $built = FALSE;
Damien McKenna
committed
/**
* State variable.
*/
public $executed = FALSE;
/**
* State variable.
*/
public $editing = FALSE;
The Great Git Migration
committed
Damien McKenna
committed
/**
*
*/
public $args = array();
/**
*
*/
public $build_info = array();
The Great Git Migration
committed
Damien McKenna
committed
/**
*
*/
public $use_ajax = FALSE;
The Great Git Migration
committed
Peter Philipp
committed
/**
* Where the results of a query will go.
*
* The array must use a numeric index starting at 0.
*
* @var array
*/
Damien McKenna
committed
public $result = array();
The Great Git Migration
committed
// May be used to override the current pager info.
Damien McKenna
committed
public $current_page = NULL;
public $items_per_page = NULL;
public $offset = NULL;
public $total_rows = NULL;
// Places to put attached renderings.
public $attachment_before = '';
public $attachment_after = '';
// Exposed widget input.
public $exposed_data = array();
public $exposed_input = array();
Daniel Wehner
committed
// Exposed widget input directly from the $form_state['values'].
Damien McKenna
committed
public $exposed_raw_input = array();
The Great Git Migration
committed
// Used to store views that were previously running if we recurse.
Damien McKenna
committed
public $old_view = array();
Daniel Wehner
committed
Daniel Wehner
committed
// To avoid recursion in views embedded into areas.
Damien McKenna
committed
public $parent_views = array();
Daniel Wehner
committed
// Is the current stored view runned as an attachment to another view.
Damien McKenna
committed
public $is_attachment = NULL;
Daniel Wehner
committed
// Stores the next steps of form items to handle.
// It's an array of stack items, which contain the form id, the type of form,
// the view, the display and some additional arguments.
// @see views_ui_add_form_to_stack()
/**
* Identifier of the current display.
*
* @var string
*/
Damien McKenna
committed
public $current_display;
Earl Miles
committed
Damien McKenna
committed
* Where the $query object will reside:.
*
* @var views_plugin_query
*/
Damien McKenna
committed
public $query = NULL;
Daniel Wehner
committed
Damien McKenna
committed
/**
* The current used display plugin.
*
* @var views_plugin_display
*/
Damien McKenna
committed
public $display_handler;
/**
* Stores all display handlers of this view.
*
* @var array[views_display]
*/
Damien McKenna
committed
public $display;
/**
* The current used style plugin.
*
* @var views_plugin_style
*/
Damien McKenna
committed
public $style_plugin;
/**
* Stored the changed options of the style plugin.
*
* @deprecated Better use $view->style_plugin->options
Damien McKenna
committed
*
* @var array
*/
Damien McKenna
committed
public $style_options;
/**
* Stores the current active row while rendering.
*
* @var int
*/
Damien McKenna
committed
public $row_index;
Damien McKenna
committed
/**
* Allow to override the url of the current view.
*
* @var string
*/
Damien McKenna
committed
public $override_url = NULL;
/**
* Allow to override the path used for generated urls.
*
* @var string
*/
Damien McKenna
committed
public $override_path = NULL;
/**
* Allow to override the used database which is used for this query.
*/
Damien McKenna
committed
public $base_database = NULL;
/**
* Here comes a list of the possible handler which are active on this view.
*/
/**
* Stores the field handlers which are initialized on this view.
Damien McKenna
committed
*
* @var array[views_handler_field]
*/
Damien McKenna
committed
public $field;
/**
* Stores the argument handlers which are initialized on this view.
Damien McKenna
committed
*
* @var array[views_handler_argument]
*/
Damien McKenna
committed
public $argument;
/**
* Stores the sort handlers which are initialized on this view.
Damien McKenna
committed
*
* @var array[views_handler_sort]
*/
Damien McKenna
committed
public $sort;
/**
* Stores the filter handlers which are initialized on this view.
Damien McKenna
committed
*
* @var array[views_handler_filter]
*/
Damien McKenna
committed
public $filter;
/**
* Stores the relationship handlers which are initialized on this view.
Damien McKenna
committed
*
* @var array[views_handler_relationship]
*/
Damien McKenna
committed
public $relationship;
/**
* Stores the area handlers for the header which are initialized on this view.
Damien McKenna
committed
*
* @var array[views_handler_area]
*/
Damien McKenna
committed
public $header;
/**
* Stores the area handlers for the footer which are initialized on this view.
Damien McKenna
committed
*
* @var array[views_handler_area]
*/
Damien McKenna
committed
public $footer;
Damien McKenna
committed
* The area handlers for the empty text which are initialized on this view.
*
* @var array[views_handler_area]
*/
Damien McKenna
committed
public $empty;
The Great Git Migration
committed
/**
Damien McKenna
committed
* Standard PHP constructor.
The Great Git Migration
committed
*/
Damien McKenna
committed
public function __construct() {
The Great Git Migration
committed
parent::init();
Damien McKenna
committed
// Make sure all of the sub objects are arrays.
The Great Git Migration
committed
foreach ($this->db_objects() as $object) {
$this->$object = array();
}
}
Earl Miles
committed
/**
* Perform automatic updates when loading or importing a view.
*
Damien McKenna
committed
* Over time, some things about Views or Drupal data has changed. this
* attempts to do some automatic updates that must happen to ensure older
* views will at least try to work.
Earl Miles
committed
*/
Damien McKenna
committed
public function update() {
Earl Miles
committed
// When views are converted automatically the base_table should be renamed
// to have a working query.
$this->base_table = views_move_table($this->base_table);
}
The Great Git Migration
committed
/**
* Returns a list of the sub-object types used by this view. These types are
* stored on the display, and are used in the build process.
*/
Damien McKenna
committed
public function display_objects() {
Daniel Wehner
committed
return array('argument', 'field', 'sort', 'filter', 'relationship', 'header', 'footer', 'empty');
The Great Git Migration
committed
}
/**
* Returns the complete list of dependent objects in a view, for the purpose
* of initialization and loading/saving to/from the database.
*/
static function db_objects() {
The Great Git Migration
committed
return array('display');
}
/**
* Set the arguments that come to this view. Usually from the URL
* but possibly from elsewhere.
*/
Damien McKenna
committed
public function set_arguments($args) {
The Great Git Migration
committed
$this->args = $args;
}
/**
* Change/Set the current page for the pager.
*/
Damien McKenna
committed
public function set_current_page($page) {
Daniel Wehner
committed
$this->current_page = $page;
Daniel Wehner
committed
// If the pager is already initialized, pass it through to the pager.
if (!empty($this->query->pager)) {
return $this->query->pager->set_current_page($page);
}
The Great Git Migration
committed
}
/**
Daniel Wehner
committed
* Get the current page from the pager.
The Great Git Migration
committed
*/
Damien McKenna
committed
public function get_current_page() {
Daniel Wehner
committed
// If the pager is already initialized, pass it through to the pager.
Daniel Wehner
committed
if (!empty($this->query->pager)) {
return $this->query->pager->get_current_page();
}
Daniel Wehner
committed
if (isset($this->current_page)) {
return $this->current_page;
}
The Great Git Migration
committed
}
/**
Daniel Wehner
committed
* Get the items per page from the pager.
The Great Git Migration
committed
*/
Damien McKenna
committed
public function get_items_per_page() {
Daniel Wehner
committed
// If the pager is already initialized, pass it through to the pager.
Daniel Wehner
committed
if (!empty($this->query->pager)) {
return $this->query->pager->get_items_per_page();
}
Daniel Wehner
committed
if (isset($this->items_per_page)) {
return $this->items_per_page;
}
The Great Git Migration
committed
}
Daniel Wehner
committed
/**
* Set the items per page on the pager.
*/
Damien McKenna
committed
public function set_items_per_page($items_per_page) {
$this->items_per_page = $items_per_page;
// If the pager is already initialized, pass it through to the pager.
if (!empty($this->query->pager)) {
$this->query->pager->set_items_per_page($items_per_page);
Daniel Wehner
committed
}
}
The Great Git Migration
committed
/**
Daniel Wehner
committed
* Get the pager offset from the pager.
The Great Git Migration
committed
*/
Damien McKenna
committed
public function get_offset() {
Daniel Wehner
committed
// If the pager is already initialized, pass it through to the pager.
Daniel Wehner
committed
if (!empty($this->query->pager)) {
return $this->query->pager->get_offset();
}
Daniel Wehner
committed
if (isset($this->offset)) {
return $this->offset;
}
The Great Git Migration
committed
}
/**
* Set the offset on the pager.
*/
Damien McKenna
committed
public function set_offset($offset) {
$this->offset = $offset;
// If the pager is already initialized, pass it through to the pager.
if (!empty($this->query->pager)) {
$this->query->pager->set_offset($offset);
}
}
Daniel Wehner
committed
/**
* Determine if the pager actually uses a pager.
*/
Damien McKenna
committed
public function use_pager() {
Daniel Wehner
committed
if (!empty($this->query->pager)) {
return $this->query->pager->use_pager();
}
}
The Great Git Migration
committed
/**
* Whether or not AJAX should be used. If AJAX is used, paging,
* tablesorting and exposed filters will be fetched via an AJAX call
* rather than a page refresh.
*/
Damien McKenna
committed
public function set_use_ajax($use_ajax) {
The Great Git Migration
committed
$this->use_ajax = $use_ajax;
}
/**
* Set the exposed filters input to an array. If unset they will be taken
* from $_GET when the time comes.
*/
Damien McKenna
committed
public function set_exposed_input($filters) {
The Great Git Migration
committed
$this->exposed_input = $filters;
}
/**
* Figure out what the exposed input for this view is.
*/
Damien McKenna
committed
public function get_exposed_input() {
The Great Git Migration
committed
if (empty($this->exposed_input)) {
$this->exposed_input = array();
The Great Git Migration
committed
// If filters are not overridden, store the 'remember' settings on the
// default display. If they are, store them on this display. This way,
// multiple displays in the same view can share the same filters and
// remember settings.
$display_id = ($this->display_handler->is_defaulted('filters')) ? 'default' : $this->current_display;
// Start with remembered input via session.
if (!empty($_SESSION['views'][$this->name][$display_id])) {
The Great Git Migration
committed
$this->exposed_input = $_SESSION['views'][$this->name][$display_id];
}
// Fetch exposed input values from $_GET. Overwrite if clashing.
foreach ($_GET as $key => $value) {
if (!in_array($key, array('page', 'q'))) {
$this->exposed_input[$key] = $value;
}
}
The Great Git Migration
committed
}
return $this->exposed_input;
}
/**
* Set the display for this view and initialize the display handler.
*/
Damien McKenna
committed
public function init_display($reset = FALSE) {
The Great Git Migration
committed
// The default display is always the first one in the list.
if (isset($this->current_display)) {
return TRUE;
}
Damien McKenna
committed
// Instantiate all displays.
The Great Git Migration
committed
foreach (array_keys($this->display) as $id) {
// Correct for shallow cloning
// Often we'll have a cloned view so we don't mess up each other's
// displays, but the clone is pretty shallow and doesn't necessarily
// clone the displays. We can tell this by looking to see if a handler
// has already been set; if it has, but $this->current_display is not
// set, then something is dreadfully wrong.
if (!empty($this->display[$id]->handler)) {
$this->display[$id] = clone $this->display[$id];
The Great Git Migration
committed
unset($this->display[$id]->handler);
}
$this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin);
if (!empty($this->display[$id]->handler)) {
$this->display[$id]->handler->localization_keys = array($id);
The Great Git Migration
committed
// Initialize the new display handler with data.
$this->display[$id]->handler->init($this, $this->display[$id]);
// If this is NOT the default display handler, let it know which is
// since it may well utilize some data from the default.
// This assumes that the 'default' handler is always first. It always
// is. Make sure of it.
if ($id != 'default') {
$this->display[$id]->handler->default_display = &$this->display['default']->handler;
The Great Git Migration
committed
}
}
}
Daniel Wehner
committed
The Great Git Migration
committed
$this->current_display = 'default';
$this->display_handler = &$this->display['default']->handler;
The Great Git Migration
committed
return TRUE;
}
/**
* Get the first display that is accessible to the user.
*
Damien McKenna
committed
* @param string|array $displays
The Great Git Migration
committed
* Either a single display id or an array of display ids.
*/
Damien McKenna
committed
public function choose_display($displays) {
The Great Git Migration
committed
if (!is_array($displays)) {
return $displays;
}
$this->init_display();
foreach ($displays as $display_id) {
if ($this->display[$display_id]->handler->access()) {
return $display_id;
}
}
return 'default';
}
/**
* Set the display as current.
*
Damien McKenna
committed
* @param string $display_id
The Great Git Migration
committed
* The id of the display to mark as current.
*/
Damien McKenna
committed
public function set_display($display_id = NULL) {
The Great Git Migration
committed
// If we have not already initialized the display, do so. But be careful.
if (empty($this->current_display)) {
$this->init_display();
// If handlers were not initialized, and no argument was sent, set up
// to the default display.
if (empty($display_id)) {
$display_id = 'default';
}
}
$display_id = $this->choose_display($display_id);
// If no display id sent in and one wasn't chosen above, we're finished.
if (empty($display_id)) {
Earl Miles
committed
return FALSE;
The Great Git Migration
committed
}
// Ensure the requested display exists.
if (empty($this->display[$display_id])) {
$display_id = 'default';
if (empty($this->display[$display_id])) {
vpr('set_display() called with invalid display id @display.', array('@display' => $display_id));
The Great Git Migration
committed
return FALSE;
}
}
// Set the current display.
$this->current_display = $display_id;
// Ensure requested display has a working handler.
if (empty($this->display[$display_id]->handler)) {
return FALSE;
}
Damien McKenna
committed
// Set a shortcut.
$this->display_handler = &$this->display[$display_id]->handler;
The Great Git Migration
committed
return TRUE;
}
/**
* Find and initialize the style plugin.
*
* Note that arguments may have changed which style plugin we use, so
* check the view object first, then ask the display handler.
*/
Damien McKenna
committed
public function init_style() {
The Great Git Migration
committed
if (isset($this->style_plugin)) {
return is_object($this->style_plugin);
}
if (!isset($this->plugin_name)) {
$this->plugin_name = $this->display_handler->get_option('style_plugin');
$this->style_options = $this->display_handler->get_option('style_options');
}
$this->style_plugin = views_get_plugin('style', $this->plugin_name);
if (empty($this->style_plugin)) {
return FALSE;
}
Damien McKenna
committed
// Init the new style handler with data..
The Great Git Migration
committed
$this->style_plugin->init($this, $this->display[$this->current_display], $this->style_options);
return TRUE;
}
Earl Miles
committed
/**
* Attempt to discover if the view has handlers missing relationships.
*
* This will try to add relationships automatically if it can, and will
* remove the handlers if it cannot.
*/
Damien McKenna
committed
public function fix_missing_relationships() {
Earl Miles
committed
if (isset($this->relationships_fixed)) {
return;
}
$this->relationships_fixed = TRUE;
// Go through all of our handler types and test them to see if they
// are missing relationships. Missing relationships can cause fatally
// broken Views.
$base_tables = array(
$this->base_table => TRUE,
'#global' => TRUE,
);
// For each relationship we have, make sure we mark the base it provides as
// available.
foreach ($this->display_handler->get_option('relationships') as $id => $options) {
Earl Miles
committed
$options['table'] = views_move_table($options['table']);
$data = views_fetch_data($options['table'], FALSE);
Jennifer Hodgdon
committed
if (isset($data[$options['field']]['relationship']['base'])) {
$base_tables[$data[$options['field']]['relationship']['base']] = TRUE;
}
Earl Miles
committed
}
$base_tables = array_keys($base_tables);
$missing_base_tables = array();
$types = views_object_types();
foreach ($types as $key => $info) {
foreach ($this->display_handler->get_option($info['plural']) as $id => $options) {
Earl Miles
committed
$options['table'] = views_move_table($options['table']);
$data = views_fetch_data($options['table'], FALSE);
Earl Miles
committed
$valid_bases = array($options['table']);
if (isset($data['table']['join'])) {
Earl Miles
committed
$valid_bases = array_merge($valid_bases, array_keys($data['table']['join']));
Earl Miles
committed
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
}
// If the base table is missing, record it so we can try to fix it.
if (!array_intersect($valid_bases, $base_tables)) {
$missing_base_tables[$options['table']][] = array('type' => $key, 'id' => $id);
}
}
}
if (!empty($missing_base_tables)) {
// This will change handlers, so make sure any existing handlers get
// tossed.
$this->display_handler->handlers = array();
$this->relationships_changed = TRUE;
$this->changed = TRUE;
// Try to fix it.
foreach ($missing_base_tables as $table => $handlers) {
$data = views_fetch_data($table);
$relationship = NULL;
// Does the missing base table have a default relationship we can
// throw in?
if (isset($data['table']['default_relationship'][$this->base_table])) {
// Create the relationship.
$info = $data['table']['default_relationship'][$this->base_table];
$relationship_options = isset($info['options']) ? $info['options'] : array();
$relationship = $this->add_item($this->current_display, 'relationship', $info['table'], $info['field'], $relationship_options);
}
foreach ($handlers as $handler) {
$options = $this->display_handler->get_option($types[$handler['type']]['plural']);
if ($relationship) {
$options[$handler['id']]['relationship'] = $relationship;
}
else {
unset($options[$handler['id']]);
}
$this->display_handler->set_option($types[$handler['type']]['plural'], $options);
}
}
}
}
The Great Git Migration
committed
/**
* Acquire and attach all of the handlers.
*/
Damien McKenna
committed
public function init_handlers() {
The Great Git Migration
committed
if (empty($this->inited)) {
Earl Miles
committed
$this->fix_missing_relationships();
The Great Git Migration
committed
foreach (views_object_types() as $key => $info) {
$this->_init_handler($key, $info);
}
$this->inited = TRUE;
}
}
Damien McKenna
committed
* Initialize the pager.
*
* Like style initialization, pager initialization is held until late
* to allow for overrides.
*/
Damien McKenna
committed
public function init_pager() {
if (empty($this->query->pager)) {
Nicolas Bourdial
committed
// If the query doesn't exist, initialize it.
if (empty($this->query)) {
$this->init_query();
}
$this->query->pager = $this->display_handler->get_plugin('pager');
if ($this->query->pager->use_pager()) {
$this->query->pager->set_current_page($this->current_page);
}
// These overrides may have been set earlier via $view->set_*
// functions.
if (isset($this->items_per_page)) {
$this->query->pager->set_items_per_page($this->items_per_page);
}
if (isset($this->offset)) {
$this->query->pager->set_offset($this->offset);
}
}
}
The Great Git Migration
committed
/**
* Create a list of base tables eligible for this view. Used primarily
* for the UI. Display must be already initialized.
*/
Damien McKenna
committed
public function get_base_tables() {
The Great Git Migration
committed
$base_tables = array(
$this->base_table => TRUE,
'#global' => TRUE,
);
foreach ($this->display_handler->get_handlers('relationship') as $handler) {
$base_tables[$handler->definition['base']] = TRUE;
}
return $base_tables;
}
/**
Daniel Wehner
committed
* Run the pre_query() on all active handlers.
The Great Git Migration
committed
*/
Damien McKenna
committed
public function _pre_query() {
The Great Git Migration
committed
foreach (views_object_types() as $key => $info) {
$handlers = &$this->$key;
$position = 0;
foreach ($handlers as $id => $handler) {
$handlers[$id]->position = $position;
$handlers[$id]->pre_query();
$position++;
}
}
}
/**
* Run the post_execute() on all active handlers.
*/
Damien McKenna
committed
public function _post_execute() {
foreach (views_object_types() as $key => $info) {
$handlers = &$this->$key;
foreach ($handlers as $id => $handler) {
$handlers[$id]->post_execute($this->result);
}
}
}
The Great Git Migration
committed
/**
* Attach all of the handlers for each type.
*
Damien McKenna
committed
* @param string $key
* One of 'argument', 'field', 'sort', 'filter', 'relationship'.
* @param array $info
The Great Git Migration
committed
* The $info from views_object_types for this object.
*/
Damien McKenna
committed
public function _init_handler($key, $info) {
The Great Git Migration
committed
// Load the requested items from the display onto the object.
$this->$key = &$this->display_handler->get_handlers($key);
The Great Git Migration
committed
// This reference deals with difficult PHP indirection.
$handlers = &$this->$key;
// Run through and test for accessibility.
foreach ($handlers as $id => $handler) {
if (!$handler->access()) {
unset($handlers[$id]);
}
}
}
/**
* Build all the arguments.
*/
Damien McKenna
committed
public function _build_arguments() {
The Great Git Migration
committed
// Initially, we want to build sorts and fields. This can change, though,
// if we get a summary view.
if (empty($this->argument)) {
return TRUE;
}
// build arguments.
$position = -1;
// Create a title for use in the breadcrumb trail.
$title = $this->display_handler->get_option('title');
$this->build_info['breadcrumb'] = array();
$breadcrumb_args = array();
$substitutions = array();
$status = TRUE;
// Iterate through each argument and process.
foreach ($this->argument as $id => $arg) {
$position++;
$argument = &$this->argument[$id];
The Great Git Migration
committed
if ($argument->broken()) {
continue;
}
$argument->set_relationship();
$arg = isset($this->args[$position]) ? $this->args[$position] : NULL;
$argument->position = $position;
if (isset($arg) || $argument->has_default_argument()) {
if (!isset($arg)) {
$arg = $argument->get_default_argument();
// make sure default args get put back.
if (isset($arg)) {
$this->args[$position] = $arg;
}
}
Damien McKenna
committed
// Set the argument, which will also validate that the argument can be
// set.
The Great Git Migration
committed
if (!$argument->set_argument($arg)) {
$status = $argument->validate_fail($arg);
break;
}
if ($argument->is_exception()) {
$arg_title = $argument->exception_title();
The Great Git Migration
committed
}
else {
$arg_title = $argument->get_title();
Daniel Wehner
committed
$argument->query($this->display_handler->use_group_by());
The Great Git Migration
committed
}
Damien McKenna
committed
// Add this argument's substitution.
The Great Git Migration
committed
$substitutions['%' . ($position + 1)] = $arg_title;
Daniel Wehner
committed
$substitutions['!' . ($position + 1)] = strip_tags(decode_entities($arg));
The Great Git Migration
committed
// Since we're really generating the breadcrumb for the item above us,
// check the default action of this argument.
if ($this->display_handler->uses_breadcrumb() && $argument->uses_breadcrumb()) {
$path = $this->get_url($breadcrumb_args);
if (strpos($path, '%') === FALSE) {
if (!empty($argument->options['breadcrumb_enable']) && !empty($argument->options['breadcrumb'])) {
$breadcrumb = $argument->options['breadcrumb'];
}
else {
$breadcrumb = $title;
}
The Great Git Migration
committed
$this->build_info['breadcrumb'][$path] = str_replace(array_keys($substitutions), $substitutions, $breadcrumb);
}
}
// Allow the argument to muck with this breadcrumb.
$argument->set_breadcrumb($this->build_info['breadcrumb']);
Damien McKenna
committed
// Test to see if we should use this argument's title.
if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) {
The Great Git Migration
committed
$title = $argument->options['title'];
}
$breadcrumb_args[] = $arg;
}
else {
// determine default condition and handle.
$status = $argument->default_action();
break;
}
Damien McKenna
committed
// Be safe with references and loops.
The Great Git Migration
committed
unset($argument);
}
// set the title in the build info.
if (!empty($title)) {
$this->build_info['title'] = $title;
The Great Git Migration
committed
}
// Store the arguments for later use.
$this->build_info['substitutions'] = $substitutions;
return $status;
}
/**
* Do some common building initialization.
*/
Damien McKenna
committed
public function init_query() {
Daniel Wehner
committed
if (!empty($this->query)) {
$class = get_class($this->query);
if ($class && $class != 'stdClass') {
// return if query is already initialized.
Daniel Wehner
committed
return TRUE;
Daniel Wehner
committed
}
}
The Great Git Migration
committed
// Create and initialize the query object.
$views_data = views_fetch_data($this->base_table);
Daniel Wehner
committed
$this->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
The Great Git Migration
committed
if (!empty($views_data['table']['base']['database'])) {
$this->base_database = $views_data['table']['base']['database'];
}
Daniel Wehner
committed
// 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);
Daniel Wehner
committed
if (empty($this->query)) {
return FALSE;
}
$this->query->init($this->base_table, $this->base_field, $query_options['options']);
return TRUE;
The Great Git Migration
committed
}
/**
* Build the query for the view.
*/
Damien McKenna
committed
public function build($display_id = NULL) {
The Great Git Migration
committed
if (!empty($this->built)) {
return;
}
if (empty($this->current_display) || $display_id) {
if (!$this->set_display($display_id)) {
return FALSE;
}
}
Earl Miles
committed
// Let modules modify the view just prior to building it.
The Great Git Migration
committed
foreach (module_implements('views_pre_build') as $module) {
$function = $module . '_views_pre_build';
$function($this);
}
// Attempt to load from cache.
// @todo Load a build_info from cache.
$start = microtime(TRUE);
The Great Git Migration
committed
// If that fails, let's build!
$this->build_info = array(
'query' => '',
'count_query' => '',
'query_args' => array(),
);
$this->init_query();
// Call a module hook and see if it wants to present us with a
// pre-built query or instruct us not to build the query for
// some reason.
Damien McKenna
committed
// @todo Implement this. Use the same mechanism Panels uses.
The Great Git Migration
committed
// Run through our handlers and ensure they have necessary information.
$this->init_handlers();
// Let the handlers interact with each other if they really want.
$this->_pre_query();
if ($this->display_handler->uses_exposed()) {
$exposed_form = $this->display_handler->get_plugin('exposed_form');