- <?php
- * @file
- * Provides the view object type and associated methods.
- */
-
- * @defgroup views_objects Objects that represent a View or part of a view
- * @{
- * These objects are the core of Views do the bulk of the direction and
- * storing of data. All database activity is in these objects.
- */
-
- * An object to contain all of the data to generate a view, plus the member
- * functions to build the view query, execute the query and render the output.
- */
- class view {
- var $base_table = 'node';
- var $base_field = 'nid';
-
-
- * The name of the view.
- *
- * @var string
- */
- var $name = "";
-
-
- * The description of the view, which is used only in the interface.
- *
- * @var string
- */
- var $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
- */
- var $tag;
-
-
- * The human readable name of the view.
- *
- * @var string
- */
- var $human_name;
-
-
- * The core version the view was created for.
- * @var int
- */
- var $core;
-
-
- * The views-api version this view was created by.
- *
- * Some examples of the variable are 3.0 or 3.0-alpha1
- *
- * @var string
- */
- var $api_version;
-
-
- * Is the view disabled.
- *
- * This value is used for exported view, to provide some module-provided
- * views which aren't enabled out-of-the-box.
- *
- * @var bool
- */
- var $disabled;
-
-
- * The translated state of the view.
- *
- * This state will be "Default", "Normal", or "Overridden". It is determined
- * at the time the view is loaded from its configuration file.
- *
- * @var string
- */
- var $type;
-
-
- * The module that originally provided this view (if any).
- *
- * @var string
- */
- var $module;
-
-
- * The storage state of the view.
- *
- * This is the machine-version of the $type variable, which represents whether
- * this view is has a default, user-created, or overridden configuration.
- * Possible values for this variable include the constants
- * VIEWS_STORAGE_NORMAL, VIEWS_STORAGE_OVERRIDE, or VIEWS_STORAGE_DEFAULT.
- *
- * @var int
- */
- var $storage;
-
-
- var $built = FALSE;
- var $executed = FALSE;
- var $editing = FALSE;
-
- var $args = array();
- var $build_info = array();
-
- var $use_ajax = FALSE;
-
-
- * Where the results of a query will go.
- *
- * The array must use a numeric index starting at 0.
- *
- * @var array
- */
- var $result = array();
-
-
- var $current_page = NULL;
- var $items_per_page = NULL;
- var $offset = NULL;
- var $total_rows = NULL;
-
-
- var $attachment_before = '';
- var $attachment_after = '';
-
-
- var $exposed_data = array();
- var $exposed_input = array();
-
- var $exposed_raw_input = array();
-
-
- var $old_view = array();
-
-
- var $parent_views = array();
-
-
- var $is_attachment = NULL;
-
-
-
-
-
-
-
-
- * Identifier of the current display.
- *
- * @var string
- */
- var $current_display;
-
-
- * Where the $query object will reside:
- *
- * @var views_plugin_query
- */
- var $query = NULL;
-
-
- * The current used display plugin.
- *
- * @var views_plugin_display
- */
- var $display_handler;
-
-
- * Stores all display handlers of this view.
- *
- * @var views_display[]
- */
- var $display;
-
-
- * The current used style plugin.
- *
- * @var views_plugin_style
- */
- var $style_plugin;
-
-
- * Stored the changed options of the style plugin.
- *
- * @deprecated Better use $view->style_plugin->options
- * @var array
- */
- var $style_options;
-
-
- * Stores the current active row while rendering.
- *
- * @var int
- */
- var $row_index;
-
-
- * Allow to override the url of the current view.
- *
- * @var string
- */
- var $override_url = NULL;
-
-
- * Allow to override the path used for generated urls.
- *
- * @var string
- */
- var $override_path = NULL;
-
-
- * Allow to override the used database which is used for this query.
- */
- var $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.
- * @var array[views_handler_field]
- */
- var $field;
-
-
- * Stores the argument handlers which are initialized on this view.
- * @var array[views_handler_argument]
- */
- var $argument;
-
-
- * Stores the sort handlers which are initialized on this view.
- * @var array[views_handler_sort]
- */
- var $sort;
-
-
- * Stores the filter handlers which are initialized on this view.
- * @var array[views_handler_filter]
- */
- var $filter;
-
-
- * Stores the relationship handlers which are initialized on this view.
- * @var array[views_handler_relationship]
- */
- var $relationship;
-
-
- * Stores the area handlers for the header which are initialized on this view.
- * @var array[views_handler_area]
- */
- var $header;
-
-
- * Stores the area handlers for the footer which are initialized on this view.
- * @var array[views_handler_area]
- */
- var $footer;
-
-
- * Stores the area handlers for the empty text which are initialized on this view.
- * @var array[views_handler_area]
- */
- var $empty;
-
-
- * Constructor
- */
- function __construct($view_data = NULL) {
- $this->display = array();
- if ($view_data) {
- foreach ($view_data as $key => $value) {
- $this->$key = $value;
- }
-
- if (isset($view_data['module'])) {
- $this->module = $view_data['module'];
- if (empty($view_data['storage']) || $view_data['storage'] == VIEWS_STORAGE_DEFAULT) {
- $this->type = t('Default');
- $this->storage = VIEWS_STORAGE_DEFAULT;
- }
- else {
- $this->type = t('Overridden');
- $this->storage = VIEWS_STORAGE_OVERRIDE;
- }
- }
- else {
- $this->type = t('Normal');
- $this->storage = VIEWS_STORAGE_NORMAL;
- }
-
-
- foreach ($this->display as $display_id => $display) {
- $this->display[$display_id] = new views_display($display['display_plugin'], $display_id, $display['display_title'], $display['display_options']);
- }
- }
- }
-
-
- * Perform automatic updates when loading or importing a view.
- *
- * Over time, some things about Views or Backdrop data has changed.
- * this attempts to do some automatic updates that must happen
- * to ensure older views will at least try to work.
- */
- function update() {
-
-
- $this->base_table = views_move_table($this->base_table);
- }
-
-
-
- * 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.
- */
- function display_objects() {
- return array('argument', 'field', 'sort', 'filter', 'relationship', 'header', 'footer', 'empty');
- }
-
-
- * Set the arguments that come to this view. Usually from the URL
- * but possibly from elsewhere.
- */
- function set_arguments($args) {
- $this->args = $args;
- }
-
-
- * Change/Set the current page for the pager.
- */
- function set_current_page($page) {
- $this->current_page = $page;
-
-
- if (!empty($this->query->pager)) {
- return $this->query->pager->set_current_page($page);
- }
-
- }
-
-
- * Get the current page from the pager.
- */
- function get_current_page() {
-
- if (!empty($this->query->pager)) {
- return $this->query->pager->get_current_page();
- }
-
- if (isset($this->current_page)) {
- return $this->current_page;
- }
- }
-
-
- * Get the items per page from the pager.
- */
- function get_items_per_page() {
-
- if (!empty($this->query->pager)) {
- return $this->query->pager->get_items_per_page();
- }
-
- if (isset($this->items_per_page)) {
- return $this->items_per_page;
- }
- }
-
-
- * Set the items per page on the pager.
- */
- function set_items_per_page($items_per_page) {
- $this->items_per_page = $items_per_page;
-
-
- if (!empty($this->query->pager)) {
- $this->query->pager->set_items_per_page($items_per_page);
- }
- }
-
-
- * Get the pager offset from the pager.
- */
- function get_offset() {
-
- if (!empty($this->query->pager)) {
- return $this->query->pager->get_offset();
- }
-
- if (isset($this->offset)) {
- return $this->offset;
- }
- }
-
-
- * Set the offset on the pager.
- */
- function set_offset($offset) {
- $this->offset = $offset;
-
-
- if (!empty($this->query->pager)) {
- $this->query->pager->set_offset($offset);
- }
- }
-
-
- * Determine if the pager actually uses a pager.
- */
- function use_pager() {
- if (!empty($this->query->pager)) {
- return $this->query->pager->use_pager();
- }
- }
-
-
- * 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.
- */
- function set_use_ajax($use_ajax) {
- $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.
- */
- function set_exposed_input($filters) {
- $this->exposed_input = $filters;
- }
-
-
- * Figure out what the exposed input for this view is.
- */
- function get_exposed_input() {
-
-
- if (empty($this->exposed_input)) {
- $this->exposed_input = $_GET;
-
- foreach (array('page', 'q') as $key) {
- if (isset($this->exposed_input[$key])) {
- unset($this->exposed_input[$key]);
- }
- }
-
-
-
-
-
-
-
- $display_id = ($this->display_handler->is_defaulted('filters')) ? 'default' : $this->current_display;
-
- if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->name][$display_id])) {
- $this->exposed_input = $_SESSION['views'][$this->name][$display_id];
- }
- }
-
- return $this->exposed_input;
- }
-
-
- * Set the display for this view and initialize the display handler.
- */
- function init_display($reset = FALSE) {
-
- if (isset($this->current_display)) {
- return TRUE;
- }
-
-
- foreach (array_keys($this->display) as $id) {
-
-
-
-
-
-
- if (!empty($this->display[$id]->handler)) {
- $this->display[$id] = clone $this->display[$id];
- 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);
-
- $this->display[$id]->handler->init($this, $this->display[$id]);
-
-
-
-
- if ($id != 'default') {
- $this->display[$id]->handler->default_display = &$this->display['default']->handler;
- }
- }
- }
-
- $this->current_display = 'default';
- $this->display_handler = &$this->display['default']->handler;
-
- return TRUE;
- }
-
-
- * Get the first display that is accessible to the user.
- *
- * @param $displays
- * Either a single display id or an array of display ids.
- */
- function choose_display($displays) {
- 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.
- *
- * @param $display_id
- * The id of the display to mark as current.
- */
- function set_display($display_id = NULL) {
-
- if (empty($this->current_display)) {
- $this->init_display();
-
-
-
- if (empty($display_id)) {
- $display_id = 'default';
- }
- }
-
- $display_id = $this->choose_display($display_id);
-
-
- if (empty($display_id)) {
- return FALSE;
- }
-
-
- if (empty($this->display[$display_id])) {
- $display_id = 'default';
- if (empty($this->display[$display_id])) {
- watchdog('views', 'set_display() called with invalid display id @display.', array('@display' => $display_id));
- return FALSE;
- }
- }
-
-
- $this->current_display = $display_id;
-
-
- if (empty($this->display[$display_id]->handler)) {
- return FALSE;
- }
-
-
- $this->display_handler = &$this->display[$display_id]->handler;
-
- 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.
- */
- function init_style() {
- 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;
- }
-
-
- $this->style_plugin->init($this, $this->display[$this->current_display], $this->style_options);
- return TRUE;
- }
-
-
- * 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.
- */
- function fix_missing_relationships() {
- if (isset($this->relationships_fixed)) {
- return;
- }
-
- $this->relationships_fixed = TRUE;
-
-
-
-
- $base_tables = array(
- $this->base_table => TRUE,
- '#global' => TRUE,
- );
-
-
-
- foreach ($this->display_handler->get_option('relationships') as $id => $options) {
- $options['table'] = views_move_table($options['table']);
- $data = views_fetch_data($options['table'], FALSE);
- if (isset($data[$options['field']]['relationship']['base'])) {
- $base_tables[$data[$options['field']]['relationship']['base']] = TRUE;
- }
- }
-
- $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) {
- $options['table'] = views_move_table($options['table']);
- $data = views_fetch_data($options['table'], FALSE);
-
- $valid_bases = array($options['table']);
- if (isset($data['table']['join'])) {
- $valid_bases = array_merge($valid_bases, array_keys($data['table']['join']));
- }
-
-
- if (!array_intersect($valid_bases, $base_tables)) {
- $missing_base_tables[$options['table']][] = array('type' => $key, 'id' => $id);
- }
- }
- }
-
- if (!empty($missing_base_tables)) {
-
-
- $this->display_handler->handlers = array();
- $this->relationships_changed = TRUE;
- $this->changed = TRUE;
-
-
- foreach ($missing_base_tables as $table => $handlers) {
- $data = views_fetch_data($table);
- $relationship = NULL;
-
-
-
- if (isset($data['table']['default_relationship'][$this->base_table])) {
-
- $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);
- }
- }
- }
- }
-
-
- * Acquire and attach all of the handlers.
- */
- function init_handlers() {
- if (empty($this->inited)) {
- $this->fix_missing_relationships();
- foreach (views_object_types() as $key => $info) {
- $this->_init_handler($key, $info);
- }
- $this->inited = TRUE;
- }
- }
-
-
- * Initialize the pager
- *
- * Like style initialization, pager initialization is held until late
- * to allow for overrides.
- */
- function init_pager() {
- if (empty($this->query->pager)) {
- $this->query->pager = $this->display_handler->get_plugin('pager');
-
- if ($this->query->pager->use_pager()) {
- $this->query->pager->set_current_page($this->current_page);
- }
-
-
-
- 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);
- }
- }
- }
-
-
- * Create a list of base tables eligible for this view. Used primarily
- * for the UI. Display must be already initialized.
- */
- function get_base_tables() {
- $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;
- }
-
-
- * Run the pre_query() on all active handlers.
- */
- function _pre_query() {
- 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.
- */
- function _post_execute() {
- foreach (views_object_types() as $key => $info) {
- $handlers = &$this->$key;
- foreach ($handlers as $id => $handler) {
- $handlers[$id]->post_execute($this->result);
- }
- }
- }
-
-
- * Attach all of the handlers for each type.
- *
- * @param $key
- * One of 'argument', 'field', 'sort', 'filter', 'relationship'
- * @param $info
- * The $info from views_object_types for this object.
- */
- function _init_handler($key, $info) {
-
- $this->$key = $this->display_handler->get_handlers($key);
-
-
- $handlers = &$this->$key;
-
-
- foreach ($handlers as $id => $handler) {
- if (!$handler->access()) {
- unset($handlers[$id]);
- }
- }
- }
-
-
- * Build all the arguments.
- */
- function _build_arguments() {
-
-
- if (empty($this->argument)) {
- return TRUE;
- }
-
-
- $position = -1;
-
-
- $title = $this->display_handler->get_option('title');
-
- $this->build_info['breadcrumb'] = array();
- $breadcrumb_args = array();
- $substitutions = array();
-
- $status = TRUE;
-
-
- foreach ($this->argument as $id => $arg) {
- $position++;
- $argument = &$this->argument[$id];
-
- 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();
-
- if (isset($arg)) {
- $this->args[$position] = $arg;
- }
-
- $argument->is_default = TRUE;
- }
-
-
- if (!$argument->set_argument($arg)) {
- $status = $argument->validate_fail($arg);
- break;
- }
-
- if ($argument->is_exception()) {
- $arg_title = $argument->exception_title();
- }
- else {
- $arg_title = $argument->get_title();
- $argument->query($this->display_handler->use_group_by());
- }
-
-
- $substitutions['%' . ($position + 1)] = $arg_title;
- $substitutions['!' . ($position + 1)] = strip_tags(decode_entities($arg));
-
-
-
- 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;
- }
- $this->build_info['breadcrumb'][$path] = str_replace(array_keys($substitutions), $substitutions, $breadcrumb);
- }
- }
-
-
- $argument->set_breadcrumb($this->build_info['breadcrumb']);
-
-
- if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) {
- $title = $argument->options['title'];
- }
-
- $breadcrumb_args[] = $arg;
- }
- else {
-
- $status = $argument->default_action();
- break;
- }
-
-
- unset($argument);
- }
-
-
- if (!empty($title)) {
- $this->build_info['title'] = $title;
- }
-
-
- $this->build_info['substitutions'] = $substitutions;
-
- return $status;
- }
-
-
- * Do some common building initialization.
- */
- function init_query() {
- if (!empty($this->query)) {
- $class = get_class($this->query);
- if ($class && $class != 'stdClass') {
-
- return TRUE;
- }
- }
-
-
- $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'];
- }
-
-
- $query_options = $this->display_handler->get_option('query');
-
-
- $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;
- }
-
-
- * Build the query for the view.
- */
- function build($display_id = NULL) {
- if (!empty($this->built)) {
- return;
- }
-
- if (empty($this->current_display) || $display_id) {
- if (!$this->set_display($display_id)) {
- return FALSE;
- }
- }
-
-
- foreach (module_implements('views_pre_build') as $module) {
- $function = $module . '_views_pre_build';
- $function($this);
- }
-
-
-
-
- $start = microtime(TRUE);
-
- $this->build_info = array(
- 'query' => '',
- 'count_query' => '',
- 'query_args' => array(),
- );
-
- $this->init_query();
-
-
-
-
-
-
-
- $this->init_handlers();
-
-
- $this->_pre_query();
-
- if ($this->display_handler->uses_exposed()) {
- $exposed_form = $this->display_handler->get_plugin('exposed_form');
-
- $errors_before = form_set_error();
- $this->exposed_widgets = $exposed_form->render_exposed_form();
-
- $errors_after = form_set_error();
-
-
-
- $exposed_errors = count($errors_after) > count($errors_before);
- if ($exposed_errors || !empty($this->build_info['abort'])) {
- $this->built = TRUE;
-
- $this->executed = TRUE;
- return empty($this->build_info['fail']);
- }
- }
-
-
- $this->_build('relationship');
-
-
- if (!empty($this->filter)) {
- $filter_groups = $this->display_handler->get_option('filter_groups');
- if ($filter_groups) {
- $this->query->set_group_operator($filter_groups['operator']);
- foreach($filter_groups['groups'] as $id => $operator) {
- $this->query->set_where_group($operator, $id);
- }
- }
- }
-
-
- $this->_build('filter');
-
- $this->build_sort = TRUE;
-
-
- if (!$this->_build_arguments()) {
- $this->build_time = microtime(TRUE) - $start;
- $this->attach_displays();
- return $this->built;
- }
-
-
-
-
- if (!$this->init_style()) {
- $this->build_info['fail'] = TRUE;
- return FALSE;
- }
-
- if ($this->style_plugin->uses_fields()) {
- $this->_build('field');
- }
-
-
- if (!empty($this->build_sort)) {
-
- if ($this->style_plugin->build_sort()) {
- $this->_build('sort');
- }
-
- $this->style_plugin->build_sort_post();
- }
-
-
- $this->_build('header');
- $this->_build('footer');
- $this->_build('empty');
-
-
- $this->display_handler->query($this->display_handler->use_group_by());
-
-
- $this->style_plugin->query($this->display_handler->use_group_by());
-
-
- if (isset($exposed_form)) {
- $exposed_form->query();
- }
-
- if (config_get('views.settings', 'sql_signature')) {
- $this->query->add_signature($this);
- }
-
-
- $this->query->alter($this);
-
-
- if (empty($this->built)) {
-
- $this->query->build($this);
- }
-
- $this->built = TRUE;
- $this->build_time = microtime(TRUE) - $start;
-
-
- $this->attach_displays();
-
-
- foreach (module_implements('views_post_build') as $module) {
- $function = $module . '_views_post_build';
- $function($this);
- }
-
- return TRUE;
- }
-
-
- * Internal method to build an individual set of handlers.
- *
- * @param string $key
- * The type of handlers (filter etc.) which should be iterated over to
- * build the relationship and query information.
- */
- function _build($key) {
- $handlers = &$this->$key;
- foreach ($handlers as $id => $data) {
-
- if (!empty($handlers[$id]) && is_object($handlers[$id])) {
- $multiple_exposed_input = array(0 => NULL);
- if ($handlers[$id]->multiple_exposed_input()) {
- $multiple_exposed_input = $handlers[$id]->group_multiple_exposed_input($this->exposed_data);
- }
- foreach ($multiple_exposed_input as $group_id) {
-
- if (!empty($this->exposed_data)) {
- $converted = FALSE;
- if ($handlers[$id]->is_a_group()) {
- $converted = $handlers[$id]->convert_exposed_input($this->exposed_data, $group_id);
- $handlers[$id]->store_group_input($this->exposed_data, $converted);
- if (!$converted) {
- continue;
- }
- }
- $rc = $handlers[$id]->accept_exposed_input($this->exposed_data);
- $handlers[$id]->store_exposed_input($this->exposed_data, $rc);
- if (!$rc) {
- continue;
- }
- }
- $handlers[$id]->set_relationship();
- $handlers[$id]->query($this->display_handler->use_group_by());
- }
- }
- }
- }
-
-
- * Execute the view's query.
- *
- * @param string $display_id
- * The machine name of the display, which should be executed.
- *
- * @return bool
- * Return whether the executing was successful, for example an argument
- * could stop the process.
- */
- function execute($display_id = NULL) {
- if (empty($this->built)) {
- if (!$this->build($display_id)) {
- return FALSE;
- }
- }
-
- if (!empty($this->executed)) {
- return TRUE;
- }
-
-
- if (!$this->display[$this->current_display]->handler->get_option('enabled') && empty($this->live_preview)) {
- $this->build_info['fail'] = TRUE;
- return FALSE;
- }
-
-
- foreach (module_implements('views_pre_execute') as $module) {
- $function = $module . '_views_pre_execute';
- $function($this);
- }
-
-
- if (!empty($this->live_preview)) {
- $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();
- }
- }
- else {
- $this->query->execute($this);
-
-
- $this->result = array_values($this->result);
- $this->_post_execute();
- if ($cache) {
- $cache->cache_set('results');
- }
- }
-
-
- foreach (module_implements('views_post_execute') as $module) {
- $function = $module . '_views_post_execute';
- $function($this);
- }
-
- $this->executed = TRUE;
- }
-
-
- * Render this view for a certain display.
- *
- * Note: You should better use just the preview function if you want to
- * render a view.
- *
- * @param string $display_id
- * The machine name of the display, which should be rendered.
- *
- * @return (string|NULL)
- * Return the output of the rendered view or NULL if something failed in the process.
- */
- function render($display_id = NULL) {
- $this->execute($display_id);
- $show_additional_queries = config_get('views.settings', 'show_additional_queries');
-
-
- if (!empty($this->build_info['fail'])) {
- return;
- }
- if (!empty($this->build_info['denied'])) {
- return;
- }
-
- backdrop_theme_initialize();
-
- $start = microtime(TRUE);
- if (!empty($this->live_preview) && $show_additional_queries) {
- $this->start_query_capture();
- }
-
- $exposed_form = $this->display_handler->get_plugin('exposed_form');
- $exposed_form->pre_render($this->result);
-
-
- if (!empty($this->live_preview)) {
- $cache = FALSE;
- }
- else {
- $cache = $this->display_handler->get_plugin('cache');
- }
- if ($cache && $cache->cache_get('output')) {
- }
- else {
- if ($cache) {
- $cache->cache_start();
- }
-
-
- if (!empty($this->query->pager)) {
- $this->query->pager->pre_render($this->result);
- }
-
-
- $this->init_style();
-
-
-
- if ($this->style_plugin->uses_fields()) {
- foreach ($this->field as $id => $handler) {
- if (!empty($this->field[$id])) {
- $this->field[$id]->pre_render($this->result);
- }
- }
- }
-
- $this->style_plugin->pre_render($this->result);
-
-
- foreach (module_implements('views_pre_render') as $module) {
- $function = $module . '_views_pre_render';
- $function($this);
- }
-
-
- foreach ($GLOBALS['base_theme_info'] as $base) {
- $function = $base->name . '_views_pre_render';
- if (function_exists($function)) {
- $function($this);
- }
- }
- $function = $GLOBALS['theme'] . '_views_pre_render';
- if (function_exists($function)) {
- $function($this);
- }
-
- $this->display_handler->output = $this->display_handler->render();
- if ($cache) {
- $cache->cache_set('output');
- }
- }
- $this->render_time = microtime(TRUE) - $start;
-
- $exposed_form->post_render($this->display_handler->output);
-
- if ($cache) {
- $cache->post_render($this->display_handler->output);
- }
-
-
- foreach (module_implements('views_post_render') as $module) {
- $function = $module . '_views_post_render';
- $function($this, $this->display_handler->output, $cache);
- }
-
-
- foreach ($GLOBALS['base_theme_info'] as $base) {
- $function = $base->name . '_views_post_render';
- if (function_exists($function)) {
- $function($this);
- }
- }
- $function = $GLOBALS['theme'] . '_views_post_render';
- if (function_exists($function)) {
- $function($this, $this->display_handler->output, $cache);
- }
-
- if (!empty($this->live_preview) && $show_additional_queries) {
- $this->end_query_capture();
- }
-
- return $this->display_handler->output;
- }
-
-
- * Render a specific field via the field ID and the row #
- *
- * Note: You might want to use views_plugin_style::render_fields as it
- * caches the output for you.
- *
- * @param string $field
- * The id of the field to be rendered.
- *
- * @param int $row
- * The row number in the $view->result which is used for the rendering.
- *
- * @return string
- * The rendered output of the field.
- */
- function render_field($field, $row) {
- if (isset($this->field[$field]) && isset($this->result[$row])) {
- return $this->field[$field]->advanced_render($this->result[$row]);
- }
- }
-
-
- * Execute the given display, with the given arguments.
- * To be called externally by whatever mechanism invokes the view,
- * such as a page callback, hook_block, etc.
- *
- * This function should NOT be used by anything external as this
- * returns data in the format specified by the display. It can also
- * have other side effects that are only intended for the 'proper'
- * use of the display, such as setting page titles and breadcrumbs.
- *
- * If you only want to view the display, use view::preview() instead.
- */
- function execute_display($display_id = NULL, $args = array()) {
- if (empty($this->current_display) || $this->current_display != $this->choose_display($display_id)) {
- if (!$this->set_display($display_id)) {
- return FALSE;
- }
- }
-
- $this->pre_execute($args);
-
-
- $output = $this->display_handler->execute();
-
- $this->post_execute();
- return $output;
- }
-
-
- * Preview the given display, with the given arguments.
- *
- * To be called externally, probably by an AJAX handler of some flavor.
- * Can also be called when views are embedded, as this guarantees
- * normalized output.
- */
- function preview($display_id = NULL, $args = array()) {
- if (empty($this->current_display) || ((!empty($display_id)) && $this->current_display != $display_id)) {
- if (!$this->set_display($display_id)) {
- return FALSE;
- }
- }
-
- $this->preview = TRUE;
- $this->pre_execute($args);
-
- $output = $this->display_handler->preview();
-
- $this->post_execute();
- return $output;
- }
-
-
- * Run attachments and let the display do what it needs to do prior
- * to running.
- */
- function pre_execute($args = array()) {
- $this->old_view[] = views_get_current_view();
- views_set_current_view($this);
- $display_id = $this->current_display;
-
-
-
- if ($args) {
- $this->set_arguments($args);
- }
-
-
- foreach (module_implements('views_pre_view') as $module) {
- $function = $module . '_views_pre_view';
- $function($this, $display_id, $this->args);
- }
-
-
- $this->dom_id = !empty($this->dom_id) ? $this->dom_id : md5($this->name . REQUEST_TIME . rand());
-
-
- $this->display_handler->pre_execute();
- }
-
-
- * Unset the current view, mostly.
- */
- function post_execute() {
-
-
-
- if ($this->old_view) {
- $old_view = array_pop($this->old_view);
- }
-
- views_set_current_view(isset($old_view) ? $old_view : FALSE);
- }
-
-
- * Run attachment displays for the view.
- */
- function attach_displays() {
- if (!empty($this->is_attachment)) {
- return;
- }
-
- if (!$this->display_handler->accept_attachments()) {
- return;
- }
-
- $this->is_attachment = TRUE;
-
- foreach ($this->display as $id => $display) {
- if (!empty($this->display[$id]->handler)) {
- $this->display[$id]->handler->attach_to($this->current_display);
- }
- }
- $this->is_attachment = FALSE;
- }
-
-
- * Called to get hook_menu() information from the view and the named display handler.
- *
- * @param $display_id
- * A display id.
- * @param $callbacks
- * A menu callback array passed from views_menu_alter().
- */
- function execute_hook_menu($display_id = NULL, &$callbacks = array()) {
-
-
-
- if (!$this->set_display($display_id)) {
- return FALSE;
- }
-
-
- if (isset($this->display_handler)) {
- return $this->display_handler->execute_hook_menu($callbacks);
- }
- }
-
-
- * Called to get hook_block information from the view and the
- * named display handler.
- */
- function execute_hook_block_list($display_id = NULL) {
-
-
-
- if (!$this->set_display($display_id)) {
- return FALSE;
- }
-
-
- if (isset($this->display_handler)) {
- return $this->display_handler->execute_hook_block_list();
- }
- }
-
-
- * Determine if the given user has access to the view. Note that
- * this sets the display handler if it hasn't been.
- */
- function access($displays = NULL, $account = NULL) {
-
- if (!empty($this->disabled)) {
- return FALSE;
- }
-
- if (!isset($this->current_display)) {
- $this->init_display();
- }
-
- if (!$account) {
- $account = $GLOBALS['user'];
- }
-
-
-
- $displays = (array)$displays;
- foreach ($displays as $display_id) {
- if (!empty($this->display[$display_id]->handler)) {
- if ($this->display[$display_id]->handler->access($account)) {
- return TRUE;
- }
- }
- }
-
- return FALSE;
- }
-
-
- * Get the view's current title. This can change depending upon how it
- * was built.
- */
- function get_title() {
- if (empty($this->display_handler)) {
- if (!$this->set_display('default')) {
- return FALSE;
- }
- }
-
-
- if (!empty($this->build_info['title'])) {
- $title = $this->build_info['title'];
- }
- else {
- $title = $this->display_handler->get_option('title');
- }
-
-
- if ($this->init_style()) {
- $title = $this->style_plugin->tokenize_value($title, 0);
- }
- return $title;
- }
-
-
- * Override the view's current title.
- *
- * The tokens in the title get's replaced before rendering.
- */
- function set_title($title) {
- $this->build_info['title'] = $title;
- return TRUE;
- }
-
-
- * Return the human readable name for a view.
- *
- * When a certain view doesn't have a human readable name return the machine readable name.
- */
- function get_human_name() {
- if (!empty($this->human_name)) {
- $human_name = $this->human_name;
- }
- else {
- $human_name = $this->name;
- }
- return $human_name;
- }
-
-
- * Force the view to build a title.
- */
- function build_title() {
- $this->init_display();
-
- if (empty($this->built)) {
- $this->init_query();
- }
-
- $this->init_handlers();
-
- $this->_build_arguments();
- }
-
-
- * Get the URL for the current view.
- *
- * This URL will be adjusted for arguments.
- */
- function get_url($args = NULL, $path = NULL) {
- if (!empty($this->override_url)) {
- return $this->override_url;
- }
-
- if (!isset($path)) {
- $path = $this->get_path();
- }
- if (!isset($args)) {
- $args = $this->args;
-
-
- $position = 0;
- if (!empty($this->argument)) {
- foreach ($this->argument as $argument_id => $argument) {
- if (!empty($argument->is_default) && !empty($argument->options['default_argument_skip_url'])) {
- unset($args[$position]);
- }
- $position++;
- }
- }
- }
-
- if (empty($path) || (empty($args) && strpos($path, '%') === FALSE)) {
- return $path;
- }
-
- $pieces = array();
- $argument_keys = isset($this->argument) ? array_keys($this->argument) : array();
- $id = current($argument_keys);
- foreach (explode('/', $path) as $piece) {
- if ($piece != '%') {
- $pieces[] = $piece;
- }
- else {
- if (empty($args)) {
-
- if ($id && !empty($this->argument[$id]->options['exception']['value'])) {
- $pieces[] = $this->argument[$id]->options['exception']['value'];
- }
- else {
- $pieces[] = '*';
- }
-
- }
- else {
- $pieces[] = array_shift($args);
- }
-
- if ($id) {
- $id = next($argument_keys);
- }
- }
- }
-
- if (!empty($args)) {
- $pieces = array_merge($pieces, $args);
- }
- return implode('/', $pieces);
- }
-
-
- * Get the base path used for this view.
- */
- function get_path() {
- if (!empty($this->override_path)) {
- return $this->override_path;
- }
-
- if (empty($this->display_handler)) {
- if (!$this->set_display('default')) {
- return FALSE;
- }
- }
- return $this->display_handler->get_path();
- }
-
-
- * Get the breadcrumb used for this view.
- *
- * @param $set
- * If true, use backdrop_set_breadcrumb() to install the breadcrumb.
- */
- function get_breadcrumb($set = FALSE) {
-
- $base = TRUE;
- $breadcrumb = array();
-
- if (!empty($this->build_info['breadcrumb'])) {
- foreach ($this->build_info['breadcrumb'] as $path => $title) {
-
-
- if ($path == config_get('system.core', 'site_frontpage')) {
- $base = FALSE;
- $title = t('Home');
- }
- if ($title) {
- $breadcrumb[] = l($title, $path, array('html' => TRUE));
- }
- }
-
- if ($set) {
- if ($base) {
- $breadcrumb = array_merge(backdrop_get_breadcrumb(), $breadcrumb);
- }
- backdrop_set_breadcrumb($breadcrumb);
- }
- }
- return $breadcrumb;
- }
-
-
- * Is this view cacheable?
- */
- function is_cacheable() {
- return $this->is_cacheable;
- }
-
-
- * Set up query capturing.
- *
- * db_query() stores the queries that it runs in global $queries,
- * bit only if dev_query is set to true. In this case, we want
- * to temporarily override that setting if it's not and we
- * can do that without forcing a db rewrite by just manipulating
- * $conf. This is kind of evil but it works.
- */
- function start_query_capture() {
- global $conf, $queries;
- if (empty($conf['dev_query'])) {
- $this->fix_dev_query = TRUE;
- $conf['dev_query'] = TRUE;
- }
-
-
-
- $this->last_query_key = NULL;
-
- if (!empty($queries)) {
- $keys = array_keys($queries);
- $this->last_query_key = array_pop($keys);
- }
- }
-
-
- * Add the list of queries run during render to buildinfo.
- *
- * @see view::start_query_capture()
- */
- function end_query_capture() {
- global $conf, $queries;
- if (!empty($this->fix_dev_query)) {
- $conf['dev_query'] = FALSE;
- }
-
-
- $temp = $queries;
-
-
-
- if (isset($this->last_query_key)) {
- foreach ($queries as $id => $query) {
- if ($id == $this->last_query_key) {
- break;
- }
-
- unset($temp[$id]);
- }
- }
-
- $this->additional_queries = $temp;
- }
-
-
- * Save the view to a configuration file.
- */
- function save() {
- $config_data = array(
- 'name' => $this->name,
- 'description' => $this->description,
- );
-
-
- if ($this->module) {
- $config_data['module'] = $this->module;
- $config_data['storage'] = VIEWS_STORAGE_OVERRIDE;
- }
- $config_data += array(
- 'tag' => $this->tag,
- 'disabled' => (boolean) $this->disabled,
- 'base_table' => $this->base_table,
- 'human_name' => $this->human_name,
- 'core' => $this->core,
- 'display' => array(),
- );
- foreach ($this->display as $display) {
- $display_config_data = array(
- 'display_title' => $display->display_title,
- 'display_plugin' => $display->display_plugin,
- 'display_options' => $display->display_options,
- );
- $config_data['display'][$display->id] = $display_config_data;
- }
-
- if (property_exists($this, 'locked')) {
- unset($this->locked);
- }
- config('views.view.' . $this->name)->setData($config_data)->save();
- $this->save_locale_strings();
-
-
- views_invalidate_cache();
- }
-
-
- * Delete the view entirely from the system.
- */
- function delete($clear = TRUE) {
- config('views.view.' . $this->name)->delete();
- cache('views')->deletePrefix('views_query:' . $this->name);
-
- if ($clear) {
-
- views_invalidate_cache();
- }
- }
-
-
- * Revert the view based on its module-provided default version (if any).
- */
- function revert($clear = TRUE) {
- config('views.view.' . $this->name)->delete();
- config_install_default_config($this->module, 'views.view.' . $this->name);
- cache('views')->deletePrefix('views_query:' . $this->name);
-
- if ($clear) {
-
- views_invalidate_cache();
- }
- }
-
-
- * Safely clone a view.
- *
- * Because views are complicated objects within objects, and PHP loves to
- * do references to everything, if a View is not properly and safely
- * cloned it will still have references to the original view, and can
- * actually cause the original view to point to objects in the cloned
- * view. This gets ugly fast.
- *
- * This will completely wipe a view clean so it can be considered fresh.
- *
- * @return view
- * The cloned view.
- */
- function clone_view() {
- $clone = clone($this);
-
- $keys = array('current_display', 'display_handler', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables', 'feed_icon');
- foreach ($keys as $key) {
- if (isset($clone->$key)) {
- unset($clone->$key);
- }
- }
- $clone->built = $clone->executed = FALSE;
- $clone->build_info = array();
- $clone->attachment_before = '';
- $clone->attachment_after = '';
- $clone->result = array();
-
-
-
- $displays = array();
- foreach ($clone->display as $id => $display) {
- $displays[$id] = clone $display;
- if (isset($displays[$id]->handler)) {
- unset($displays[$id]->handler);
- }
- }
- $clone->display = $displays;
-
- return $clone;
- }
-
-
- * Unset references so that a $view object may be properly garbage
- * collected.
- */
- function destroy() {
- foreach (array_keys($this->display) as $display_id) {
- if (isset($this->display[$display_id]->handler)) {
- $this->display[$display_id]->handler->destroy();
- unset($this->display[$display_id]->handler);
- }
- }
-
- foreach (views_object_types() as $type => $info) {
- if (isset($this->$type)) {
- $handlers = &$this->$type;
- foreach ($handlers as $id => $item) {
- $handlers[$id]->destroy();
- }
- unset($handlers);
- }
- }
-
- if (isset($this->style_plugin)) {
- $this->style_plugin->destroy();
- unset($this->style_plugin);
- }
-
-
- if (isset($this->display_handler)) {
- unset($this->display_handler);
- }
-
- if (isset($this->current_display)) {
- unset($this->current_display);
- }
-
- if (isset($this->query)) {
- unset($this->query);
- }
-
- $keys = array('current_display', 'display_handler', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'result', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'many_to_one_tables');
- foreach ($keys as $key) {
- if (isset($this->$key)) {
- unset($this->$key);
- }
- }
-
-
-
- $keys = array('items_per_page', 'offset', 'current_page');
- foreach ($keys as $key) {
- if (isset($this->$key)) {
- $this->$key = NULL;
- }
- }
-
- $this->built = $this->executed = FALSE;
- $this->build_info = array();
- $this->attachment_before = '';
- $this->attachment_after = '';
- }
-
-
- * Make sure the view is completely valid.
- *
- * @return
- * TRUE if the view is valid; an array of error strings if it is not.
- */
- function validate() {
- $this->init_display();
-
- $errors = array();
- $this->display_errors = NULL;
-
- $current_display = $this->current_display;
- foreach ($this->display as $id => $display) {
- if ($display->handler) {
- if (!empty($display->deleted)) {
- continue;
- }
-
- $result = $this->display[$id]->handler->validate();
- if (!empty($result) && is_array($result)) {
- $errors = array_merge($errors, $result);
-
- $this->display_errors[$id] = TRUE;
- }
- }
- }
-
- $this->set_display($current_display);
- return $errors ? $errors : TRUE;
- }
-
-
- * Find and initialize the localization plugin.
- *
- * @return bool
- * Whether the active plugin does handle translation or not. FALSE for the
- * plugin "none", or if no plugin was available.
- *
- * @see unpack_options()
- */
- public function init_localization() {
-
- if (!isset($this->localization_plugin->translate)) {
- $this->localization_plugin = views_get_plugin('localization', views_get_localization_plugin());
-
-
-
-
- if (empty($this->localization_plugin)) {
- $this->localization_plugin = views_get_plugin('localization', 'none');
-
-
- if (is_null($this->localization_plugin)) {
- return FALSE;
- }
- }
-
-
- $this->localization_plugin->init($this);
- }
-
-
-
- return $this->localization_plugin->translate;
- }
-
-
- * Determine whether a view supports admin string translation.
- */
- function is_translatable() {
-
-
- return (!isset($this->type) || in_array($this->type, array(t('Normal'), t('Overridden')))) ? TRUE : FALSE;
- }
-
-
- * Send strings for localization.
- */
- public function save_locale_strings() {
- $this->process_locale_strings('save');
- }
-
-
- * Delete localized strings.
- */
- public function delete_locale_strings() {
- $this->process_locale_strings('delete');
- }
-
-
- * Process strings for localization or deletion.
- */
- public function process_locale_strings($op) {
-
-
- if ($this->is_translatable() && $this->init_display() && $this->init_localization()) {
- $this->localization_plugin->process_locale_strings($op);
- }
- }
-
-
- * Add a new display handler to the view, automatically creating an id.
- *
- * @param $type
- * The plugin type from the views plugin data. Defaults to 'page'.
- * @param $title
- * The title of the display; optional, may be filled in from default.
- * @param $id
- * The id to use.
- * @return
- * The key to the display in $view->display, so that the new display
- * can be located.
- */
- function add_display($type = 'page', $title = NULL, $id = NULL) {
- if (empty($type)) {
- return FALSE;
- }
-
- $plugin = views_fetch_plugin_data('display', $type);
- if (empty($plugin)) {
- $plugin['title'] = t('Broken');
- }
-
-
- if (empty($id)) {
- $id = $this->generate_display_id($type);
- if ($id !== 'default') {
- preg_match("/[0-9]+/", $id, $count);
- $count = $count[0];
- }
- else {
- $count = '';
- }
-
- if (empty($title)) {
- if ($count > 1) {
- $title = $plugin['title'] . ' ' . $count;
- }
- else {
- $title = $plugin['title'];
- }
- }
- }
-
-
- $display = new views_display($type, $id, $title);
-
-
- $this->display[$id] = $display;
- return $id;
- }
-
-
- * Generate a display id of a certain plugin type.
- *
- * @param $type
- * Which plugin should be used for the new display id.
- */
- function generate_display_id($type) {
-
-
- if ($type == 'default') {
- return 'default';
- }
-
- $id = $type . '_1';
- $count = 1;
-
-
-
- while (!empty($this->display[$id])) {
- $id = $type . '_' . ++$count;
- }
-
- return $id;
- }
-
-
- * Generates a unique ID for an item.
- *
- * These items are typically fields, filters, sort criteria, or arguments.
- *
- * @param $requested_id
- * The requested ID for the item.
- * @param $existing_items
- * An array of existing items, keyed by their IDs.
- *
- * @return
- * A unique ID. This will be equal to $requested_id if no item with that ID
- * already exists. Otherwise, it will be appended with an integer to make
- * it unique, e.g. "{$requested_id}_1", "{$requested_id}_2", etc.
- */
- public static function generate_item_id($requested_id, $existing_items) {
- $count = 0;
- $id = $requested_id;
- while (!empty($existing_items[$id])) {
- $id = $requested_id . '_' . ++$count;
- }
- return $id;
- }
-
-
- * Create a new display and a display handler for it.
- * @param $type
- * The plugin type from the views plugin data. Defaults to 'page'.
- * @param $title
- * The title of the display; optional, may be filled in from default.
- * @param $id
- * The id to use.
- * @return views_plugin_display
- * A reference to the new handler object.
- */
- function &new_display($type = 'page', $title = NULL, $id = NULL) {
- $id = $this->add_display($type, $title, $id);
-
-
- $this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin);
- if (empty($this->display[$id]->handler)) {
-
-
- $this->display[$id]->handler = views_get_plugin('display', 'default');
- }
-
- if (!empty($this->display[$id]->handler)) {
-
- $this->display[$id]->handler->init($this, $this->display[$id]);
-
- if ($id != 'default') {
- $this->display[$id]->handler->default_display = &$this->display['default']->handler;
- }
- }
-
- return $this->display[$id]->handler;
- }
-
-
- * Add an item with a handler to the view.
- *
- * These items may be fields, filters, sort criteria, or arguments.
- */
- function add_item($display_id, $type, $table, $field, $options = array(), $id = NULL) {
- $types = views_object_types();
- $this->set_display($display_id);
-
- $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
-
- if (empty($id)) {
- $id = $this->generate_item_id($field, $fields);
- }
-
- $new_item = array(
- 'id' => $id,
- 'table' => $table,
- 'field' => $field,
- ) + $options;
-
- if (!empty($types[$type]['type'])) {
- $handler_type = $types[$type]['type'];
- }
- else {
- $handler_type = $type;
- }
-
- $handler = views_get_handler($table, $field, $handler_type);
-
- $fields[$id] = $new_item;
- $this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
-
- return $id;
- }
-
-
- * Get an array of items for the current display.
- */
- function get_items($type, $display_id = NULL) {
- $this->set_display($display_id);
-
- if (!isset($display_id)) {
- $display_id = $this->current_display;
- }
-
-
- $types = views_object_types();
- return $this->display[$display_id]->handler->get_option($types[$type]['plural']);
- }
-
-
- * Get the configuration of an item (field/sort/filter/etc) on a given
- * display.
- */
- function get_item($display_id, $type, $id) {
-
- $types = views_object_types();
-
- $this->set_display($display_id);
-
-
- $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
-
- return isset($fields[$id]) ? $fields[$id] : NULL;
- }
-
-
- * Set the configuration of an item (field/sort/filter/etc) on a given
- * display.
- *
- * Pass in NULL for the $item to remove an item.
- */
- function set_item($display_id, $type, $id, $item) {
-
- $types = views_object_types();
-
- $this->set_display($display_id);
-
-
- $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
- if (isset($item)) {
- $fields[$id] = $item;
- }
- else {
- unset($fields[$id]);
- }
-
-
- $this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
- }
-
-
- * Set an option on an item.
- *
- * Use this only if you have just 1 or 2 options to set; if you have
- * many, consider getting the item, adding the options and doing
- * set_item yourself.
- */
- function set_item_option($display_id, $type, $id, $option, $value) {
- $item = $this->get_item($display_id, $type, $id);
- $item[$option] = $value;
- $this->set_item($display_id, $type, $id, $item);
- }
- }
-
- * A display type in a view.
- */
- class views_display {
-
-
- * The name of the plugin that provides the functionality of this display.
- *
- * @var string
- */
- var $display_plugin;
-
-
- * The machine name of this display.
- *
- * @var string
- */
- var $id;
-
-
- * The human-readable title of this display.
- *
- * @var string
- */
- var $title;
-
-
- * Stores all options of the display, like fields, filters etc.
- *
- * @var array
- */
- var $display_options;
-
-
- * The position of this display relative to other displays.
- *
- * @var int
- */
- var $position = 0;
-
- function __construct($type, $id, $title, $display_options = array()) {
- $this->display_plugin = $type;
- $this->id = $id;
- $this->display_title = $title;
- $this->display_options = $display_options;
- }
- }
-
- * @}
- */