Public Member Functions | Static Public Member Functions | Public Attributes

view Class Reference
[Objects that represent a View or part of a view.]

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. More...

Inheritance diagram for view:
views_db_object

List of all members.

Public Member Functions

 __construct ()
 Constructor.
 update ()
 Perform automatic updates when loading or importing a view.
 display_objects ()
 Returns a list of the sub-object types used by this view.
 set_arguments ($args)
 Set the arguments that come to this view.
 set_current_page ($page)
 Change/Set the current page for the pager.
 get_current_page ()
 Get the current page from the pager.
 get_items_per_page ()
 Get the items per page from the pager.
 set_items_per_page ($items_per_page)
 Set the items per page on the pager.
 get_offset ()
 Get the pager offset from the pager.
 set_offset ($offset)
 Set the offset on the pager.
 use_pager ()
 Determine if the pager actually uses a pager.
 set_use_ajax ($use_ajax)
 Whether or not AJAX should be used.
 set_exposed_input ($filters)
 Set the exposed filters input to an array.
 get_exposed_input ()
 Figure out what the exposed input for this view is.
 init_display ($reset=FALSE)
 Set the display for this view and initialize the display handler.
 choose_display ($displays)
 Get the first display that is accessible to the user.
 set_display ($display_id=NULL)
 Set the display as current.
 init_style ()
 Find and initialize the style plugin.
 fix_missing_relationships ()
 Attempt to discover if the view has handlers missing relationships.
 init_handlers ()
 Acquire and attach all of the handlers.
 init_pager ()
 Initialize the pager.
 get_base_tables ()
 Create a list of base tables eligible for this view.
 _pre_query ()
 Run the pre_query() on all active handlers.
 _post_execute ()
 Run the post_execute() on all active handlers.
 _init_handler ($key, $info)
 Attach all of the handlers for each type.
 _build_arguments ()
 Build all the arguments.
 init_query ()
 Do some common building initialization.
 build ($display_id=NULL)
 Build the query for the view.
 _build ($key)
 Internal method to build an individual set of handlers.
 execute ($display_id=NULL)
 Execute the view's query.
 render ($display_id=NULL)
 Render this view for display.
 render_field ($field, $row)
 Render a specific field via the field ID and the row #.
 execute_display ($display_id=NULL, $args=array())
 Execute the given display, with the given arguments.
 preview ($display_id=NULL, $args=array())
 Preview the given display, with the given arguments.
 pre_execute ($args=array())
 Run attachments and let the display do what it needs to do prior to running.
 post_execute ()
 Unset the current view, mostly.
 attach_displays ()
 Run attachment displays for the view.
 execute_hook_menu ($display_id=NULL, &$callbacks=array())
 Called to get hook_menu() information from the view and the named display handler.
 execute_hook_block_list ($display_id=NULL)
 Called to get hook_block information from the view and the named display handler.
 access ($displays=NULL, $account=NULL)
 Determine if the given user has access to the view.
 get_title ()
 Get the view's current title.
 set_title ($title)
 Override the view's current title.
 get_human_name ()
 Return the human readable name for a view.
 build_title ()
 Force the view to build a title.
 get_url ($args=NULL, $path=NULL)
 Get the URL for the current view.
 get_path ()
 Get the base path used for this view.
 get_breadcrumb ($set=FALSE)
 Get the breadcrumb used for this view.
 is_cacheable ()
 Is this view cacheable?
 start_query_capture ()
 Set up query capturing.
 end_query_capture ()
 Add the list of queries run during render to buildinfo.
 save ()
 Save the view to the database.
 _save_rows ($key)
 Save a row to the database for the given key, which is one of the keys from view::db_objects().
 delete ($clear=TRUE)
 Delete the view from the database.
 export ($indent= '')
 Export a view as PHP code.
 copy ()
 Make a copy of this view that has been sanitized of all database IDs and handlers and other stuff.
 clone_view ()
 Safely clone a view.
 destroy ()
 Unset references so that a $view object may be properly garbage collected.
 validate ()
 Make sure the view is completely valid.
 init_localization ()
 Find and initialize the localizer plugin.
 is_translatable ()
 Determine whether a view supports admin string translation.
 save_locale_strings ()
 Send strings for localization.
 delete_locale_strings ()
 Delete localized strings.
 export_locale_strings ()
 Export localized strings.
 process_locale_strings ($op)
 Process strings for localization, deletion or export to code.
 init ($init=TRUE)
 Initialize this object, setting values from schema defaults.
 save_row ($update=NULL)
 Write the row to the database.
 load_row ($data)
 Load the object with a row from the database.
 export_row ($identifier=NULL, $indent= '')
 Export a loaded row, such as an argument, field or the view itself to PHP code.
 add_display ($type= 'page', $title=NULL, $id=NULL)
 Add a new display handler to the view, automatically creating an id.
 generate_display_id ($type)
 Generate a display id of a certain plugin type.
new_display ($type= 'page', $title=NULL, $id=NULL)
 Create a new display and a display handler for it.
 add_item ($display_id, $type, $table, $field, $options=array(), $id=NULL)
 Add an item with a handler to the view.
 get_items ($type, $display_id=NULL)
 Get an array of items for the current display.
 get_item ($display_id, $type, $id)
 Get the configuration of an item (field/sort/filter/etc) on a given display.
 set_item ($display_id, $type, $id, $item)
 Set the configuration of an item (field/sort/filter/etc) on a given display.
 set_item_option ($display_id, $type, $id, $option, $value)
 Set an option on an item.

Static Public Member Functions

static db_objects ()
 Returns the complete list of dependent objects in a view, for the purpose of initialization and loading/saving to/from the database.
static load_views ()
 Static factory method to load a list of views based upon a $where clause.
static generate_item_id ($requested_id, $existing_items)
 Generates a unique ID for an item.

Public Attributes

 $db_table = 'views_view'
 $base_table = 'node'
 $base_field = 'nid'
 $name = ""
 $vid
 $description
 $tag
 $human_name
 $core
 $api_version
 $disabled
 $built = FALSE
 $executed = FALSE
 $editing = FALSE
 $args = array()
 $build_info = array()
 $use_ajax = FALSE
 $result = array()
 $current_page = NULL
 $items_per_page = NULL
 $offset = NULL
 $total_rows = NULL
 $attachment_before = ''
 $attachment_after = ''
 $exposed_data = array()
 $exposed_input = array()
 $exposed_raw_input = array()
 $old_view = array()
 $parent_views = array()
 $is_attachment = NULL
 $current_display
 $query = NULL
 $display_handler
 $display
 $style_plugin
 $style_options
 $row_index
 $override_url = NULL
 $override_path = NULL
 $base_database = NULL
 Allow to override the used database which is used for this query.
 $field
 $argument
 $sort
 $filter
 $relationship
 $header
 $footer
 $empty

Detailed Description

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.

Definition at line 18 of file view.inc.


Constructor & Destructor Documentation

view::__construct (  ) 

Constructor.

Definition at line 252 of file view.inc.

References db_objects(), and views_db_object::init().

                         {
    parent::init();
    // Make sure all of our sub objects are arrays.
    foreach ($this->db_objects() as $object) {
      $this->$object = array();
    }
  }


Member Function Documentation

view::_build ( key  ) 

Internal method to build an individual set of handlers.

Definition at line 1039 of file view.inc.

Referenced by build().

                        {
    $handlers = &$this->$key;
    foreach ($handlers as $id => $data) {
      if (!empty($handlers[$id]) && is_object($handlers[$id])) {
        // Give this handler access to the exposed filter input.
        if (!empty($this->exposed_data)) {
          $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());
      }
    }
  }

view::_build_arguments (  ) 

Build all the arguments.

Definition at line 747 of file view.inc.

References get_url().

Referenced by build(), and build_title().

                              {
    // 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];

      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;
          }
          // remember that this argument was computed, not passed on the URL.
          $argument->is_default = TRUE;
        }

        // Set the argument, which will also validate that the argument can be set.
        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());
        }

        // Add this argument's substitution
        $substitutions['%' . ($position + 1)] = $arg_title;
        $substitutions['!' . ($position + 1)] = strip_tags(decode_entities($arg));

        // 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;
            }
            $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']);

        // Test to see if we should use this argument's title
        if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) {
          $title = $argument->options['title'];
        }

        $breadcrumb_args[] = $arg;
      }
      else {
        // determine default condition and handle.
        $status = $argument->default_action();
        break;
      }

      // Be safe with references and loops:
      unset($argument);
    }

    // set the title in the build info.
    if (!empty($title)) {
      $this->build_info['title'] = $title;
    }

    // Store the arguments for later use.
    $this->build_info['substitutions'] = $substitutions;

    return $status;
  }

view::_init_handler ( key,
info 
)

Attach all of the handlers for each type.

Parameters:
$key One of 'argument', 'field', 'sort', 'filter', 'relationship'
$info The $info from views_object_types for this object.

Definition at line 729 of file view.inc.

Referenced by init_handlers().

                                      {
    // Load the requested items from the display onto the object.
    $this->$key = $this->display_handler->get_handlers($key);

    // 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]);
      }
    }
  }

view::_post_execute (  ) 

Run the post_execute() on all active handlers.

Definition at line 712 of file view.inc.

References views_object_types().

Referenced by execute().

                           {
    foreach (views_object_types() as $key => $info) {
      $handlers = &$this->$key;
      foreach ($handlers as $id => $handler) {
        $handlers[$id]->post_execute($this->result);
      }
    }
  }

view::_pre_query (  ) 

Run the pre_query() on all active handlers.

Definition at line 697 of file view.inc.

References views_object_types().

Referenced by build().

                        {
    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++;
      }
    }
  }

view::_save_rows ( key  ) 

Save a row to the database for the given key, which is one of the keys from view::db_objects().

Definition at line 1739 of file view.inc.

Referenced by save().

                            {
    $count = 0;
    foreach ($this->$key as $position => $object) {
      $object->position = ++$count;
      $object->vid = $this->vid;
      $object->save_row();
    }
  }

view::access ( displays = NULL,
account = NULL 
)

Determine if the given user has access to the view.

Note that this sets the display handler if it hasn't been.

Definition at line 1378 of file view.inc.

References init_display().

                                                     {
    // Noone should have access to disabled views.
    if (!empty($this->disabled)) {
      return FALSE;
    }

    if (!isset($this->current_display)) {
      $this->init_display();
    }

    if (!$account) {
      $account = $GLOBALS['user'];
    }

    // We can't use choose_display() here because that function
    // calls this one.
    $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;
  }

views_db_object::add_display ( type = 'page',
title = NULL,
id = NULL 
) [inherited]

Add a new display handler to the view, automatically creating an id.

Parameters:
$type The plugin type from the views plugin data. Defaults to 'page'.
$title The title of the display; optional, may be filled in from default.
$id The id to use.
Returns:
The key to the display in $view->display, so that the new display can be easily located.

Definition at line 2186 of file view.inc.

References views_db_object::generate_display_id(), and views_fetch_plugin_data().

Referenced by views_db_object::new_display().

                                                                  {
    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'];
        }
      }
    }

    // Create the new display object
    $display = new views_display;
    $display->options($type, $id, $title);

    // Add the new display object to the view.
    $this->display[$id] = $display;
    return $id;
  }

views_db_object::add_item ( display_id,
type,
table,
field,
options = array(),
id = NULL 
) [inherited]

Add an item with a handler to the view.

These items may be fields, filters, sort criteria, or arguments.

Definition at line 2314 of file view.inc.

References views_db_object::generate_item_id(), views_get_handler(), and views_object_types().

Referenced by fix_missing_relationships().

                                                                                        {
    $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;
  }

view::attach_displays (  ) 

Run attachment displays for the view.

Definition at line 1315 of file view.inc.

Referenced by build().

                             {
    if (!empty($this->is_attachment)) {
      return;
    }

    if (!$this->display_handler->accept_attachments()) {
      return;
    }

    $this->is_attachment = TRUE;
    // Give other displays an opportunity to attach to the view.
    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;
  }

view::build ( display_id = NULL  ) 

Build the query for the view.

Definition at line 892 of file view.inc.

References _build(), _build_arguments(), _pre_query(), attach_displays(), init_handlers(), init_query(), init_style(), and set_display().

Referenced by execute().

                                     {
    if (!empty($this->built)) {
      return;
    }

    if (empty($this->current_display) || $display_id) {
      if (!$this->set_display($display_id)) {
        return FALSE;
      }
    }

    // Let modules modify the view just prior to building it.
    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);
    // 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.
    // @todo: Implement this. Use the same mechanism Panels uses.

    // 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');
      $this->exposed_widgets = $exposed_form->render_exposed_form();
      if (form_set_error() || !empty($this->build_info['abort'])) {
        $this->built = TRUE;
        // Don't execute the query, but rendering will still be executed to display the empty text.
        $this->executed = TRUE;
        return empty($this->build_info['fail']);
      }
    }

    // Build all the relationships first thing.
    $this->_build('relationship');

    // Set the filtering groups.
    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);
        }
      }
    }

    // Build all the filters.
    $this->_build('filter');

    $this->build_sort = TRUE;

    // Arguments can, in fact, cause this whole thing to abort.
    if (!$this->_build_arguments()) {
      $this->build_time = microtime(TRUE) - $start;
      $this->attach_displays();
      return $this->built;
    }

    // Initialize the style; arguments may have changed which style we use,
    // so waiting as long as possible is important. But we need to know
    // about the style when we go to build fields.
    if (!$this->init_style()) {
      $this->build_info['fail'] = TRUE;
      return FALSE;
    }

    if ($this->style_plugin->uses_fields()) {
      $this->_build('field');
    }

    // Build our sort criteria if we were instructed to do so.
    if (!empty($this->build_sort)) {
      // Allow the style handler to deal with sorting.
      if ($this->style_plugin->build_sort()) {
        $this->_build('sort');
      }
      // allow the plugin to build second sorts as well.
      $this->style_plugin->build_sort_post();
    }

    // Allow area handlers to affect the query.
    $this->_build('header');
    $this->_build('footer');
    $this->_build('empty');

    // Allow display handler to affect the query:
    $this->display_handler->query($this->display_handler->use_group_by());

    // Allow style handler to affect the query:
    $this->style_plugin->query($this->display_handler->use_group_by());

    // Allow exposed form to affect the query:
    if (isset($exposed_form)) {
      $exposed_form->query();
    }

    if (variable_get('views_sql_signature', FALSE)) {
      $this->query->add_signature($this);
    }

    // Let modules modify the query just prior to finalizing it.
    $this->query->alter($this);

    // Only build the query if we weren't interrupted.
    if (empty($this->built)) {
      // Build the necessary info to execute the query.
      $this->query->build($this);
    }

    $this->built = TRUE;
    $this->build_time = microtime(TRUE) - $start;

    // Attach displays
    $this->attach_displays();

    // Let modules modify the view just after building it.
    foreach (module_implements('views_post_build') as $module) {
      $function = $module . '_views_post_build';
      $function($this);
    }

    return TRUE;
  }

view::build_title (  ) 

Force the view to build a title.

Definition at line 1460 of file view.inc.

References _build_arguments(), init_display(), init_handlers(), and init_query().

                         {
    $this->init_display();

    if (empty($this->built)) {
      $this->init_query();
    }

    $this->init_handlers();

    $this->_build_arguments();
  }

view::choose_display ( displays  ) 

Get the first display that is accessible to the user.

Parameters:
$displays Either a single display id or an array of display ids.

Definition at line 461 of file view.inc.

References init_display().

Referenced by execute_display(), and set_display().

                                     {
    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';
  }

view::clone_view (  ) 

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.

Returns:
view The cloned view.

Definition at line 1837 of file view.inc.

                        {
    $clone = version_compare(phpversion(), '5.0') < 0 ? $this : 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();

    // shallow cloning means that all the display objects
    // *were not cloned*. We must clone them ourselves.
    $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;
  }

view::copy (  ) 

Make a copy of this view that has been sanitized of all database IDs and handlers and other stuff.

I'd call this clone() but it's reserved.

Definition at line 1817 of file view.inc.

References export().

                  {
    $code = $this->export();
    eval($code);
    return $view;
  }

static view::db_objects (  )  [static]

Returns the complete list of dependent objects in a view, for the purpose of initialization and loading/saving to/from the database.

Definition at line 286 of file view.inc.

Referenced by __construct(), delete(), load_views(), save(), and views_load_display_records().

                               {
    return array('display');
  }

view::delete ( clear = TRUE  ) 

Delete the view from the database.

Definition at line 1751 of file view.inc.

References db_objects().

                                 {
    if (empty($this->vid)) {
      return;
    }

    db_delete('views_view')
      ->condition('vid', $this->vid)
      ->execute();
    // Delete from all of our subtables as well.
    foreach ($this->db_objects() as $key) {
      db_delete('views_'. $key)
        ->condition('vid', $this->vid)
        ->execute();
    }

    cache_clear_all('views_query:' . $this->name, 'cache_views');

    if ($clear) {
      cache_clear_all(); // this clears the block and page caches only.
      menu_rebuild(); // force a menu rebuild when a view is deleted.
    }
  }

view::delete_locale_strings (  ) 

Delete localized strings.

Definition at line 1988 of file view.inc.

References process_locale_strings().

                                   {
    $this->process_locale_strings('delete');
  }

view::destroy (  ) 

Unset references so that a $view object may be properly garbage collected.

Definition at line 1870 of file view.inc.

References views_object_types().

                     {
    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);
    }

    // Clear these to make sure the view can be processed/used again.
    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);
      }
    }
    $this->built = $this->executed = FALSE;
    $this->build_info = array();
    $this->attachment_before = '';
    $this->attachment_after = '';
  }

view::display_objects (  ) 

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.

Definition at line 278 of file view.inc.

                             {
    return array('argument', 'field', 'sort', 'filter', 'relationship', 'header', 'footer', 'empty');
  }

view::end_query_capture (  ) 

Add the list of queries run during render to buildinfo.

See also:
view::start_query_capture()

Definition at line 1626 of file view.inc.

Referenced by render().

                               {
    global $conf, $queries;
    if (!empty($this->fix_dev_query)) {
      $conf['dev_query'] = FALSE;
    }

    // make a copy of the array so we can manipulate it with array_splice.
    $temp = $queries;

    // Scroll through the queries until we get to our last query key.
    // Unset anything in our temp array.
    if (isset($this->last_query_key)) {
      while (list($id, $query) = each($queries)) {
        if ($id == $this->last_query_key) {
          break;
        }

        unset($temp[$id]);
      }
    }

    $this->additional_queries = $temp;
  }

view::execute ( display_id = NULL  ) 

Execute the view's query.

Definition at line 1060 of file view.inc.

References _post_execute(), build(), and vpr().

Referenced by render().

                                       {
    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;
    }
    else {
      $cache = $this->display_handler->get_plugin('cache');
    }
    if ($cache && $cache->cache_get('results')) {
      if($this->query->pager->use_pager()) {
        $this->query->pager->total_items = $this->total_rows;
        $this->query->pager->update_page_info();
      }
      vpr('Used cached results');
    }
    else {
      $this->query->execute($this);
      $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;
  }

view::execute_display ( display_id = NULL,
args = array() 
)

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 simply want to view the display, use view::preview() instead.

Definition at line 1234 of file view.inc.

References choose_display(), post_execute(), pre_execute(), and set_display().

                                                                {
    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);

    // Execute the view
    $output = $this->display_handler->execute();

    $this->post_execute();
    return $output;
  }

view::execute_hook_block_list ( display_id = NULL  ) 

Called to get hook_block information from the view and the named display handler.

Definition at line 1360 of file view.inc.

References set_display().

                                                       {
    // Prepare the view with the information we have.

    // This was probably already called, but it's good to be safe.
    if (!$this->set_display($display_id)) {
      return FALSE;
    }

    // Execute the view
    if (isset($this->display_handler)) {
      return $this->display_handler->execute_hook_block_list();
    }
  }

view::execute_hook_menu ( display_id = NULL,
&$  callbacks = array() 
)

Called to get hook_menu() information from the view and the named display handler.

Parameters:
$display_id A display id.
$callbacks A menu callback array passed from views_menu_alter().

Definition at line 1342 of file view.inc.

References set_display().

                                                                        {
    // Prepare the view with the information we have.

    // This was probably already called, but it's good to be safe.
    if (!$this->set_display($display_id)) {
      return FALSE;
    }

    // Execute the view
    if (isset($this->display_handler)) {
      return $this->display_handler->execute_hook_menu($callbacks);
    }
  }

view::export ( indent = ''  ) 

Export a view as PHP code.

Definition at line 1777 of file view.inc.

References export_locale_strings(), views_db_object::export_row(), init_display(), init_localization(), init_query(), and views_api_version().

Referenced by copy().

                                {
    $this->init_display();
    $this->init_query();
    $output = '';
    $output .= $this->export_row('view', $indent);
    // Set the API version
    $output .= $indent . '$view->api_version = \'' . views_api_version() . "';\n";
    $output .= $indent . '$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */' . "\n";

    foreach ($this->display as $id => $display) {
      $output .= "\n" . $indent . "/* Display: $display->display_title */\n";
      $output .= $indent . '$handler = $view->new_display(' . ctools_var_export($display->display_plugin, $indent) . ', ' . ctools_var_export($display->display_title, $indent) . ', \'' . $id . "');\n";
      if (empty($display->handler)) {
        // @todo -- probably need a method of exporting broken displays as
        // they may simply be broken because a module is not installed. That
        // does not invalidate the display.
        continue;
      }

      $output .= $display->handler->export_options($indent, '$handler->options');
    }

    // Give the localization system a chance to export translatables to code.
    if ($this->init_localization()) {
      $this->export_locale_strings('export');
      $translatables = $this->localization_plugin->export_render($indent);
      if (!empty($translatables)) {
        $output .= $translatables;
      }
    }

    return $output;
  }

view::export_locale_strings (  ) 

Export localized strings.

Definition at line 1995 of file view.inc.

References process_locale_strings().

Referenced by export().

                                   {
    $this->process_locale_strings('export');
  }

views_db_object::export_row ( identifier = NULL,
indent = '' 
) [inherited]

Export a loaded row, such as an argument, field or the view itself to PHP code.

Parameters:
$identifier The variable to assign the PHP code for this object to.
$indent An optional indentation for prettifying nested code.

Definition at line 2131 of file view.inc.

Referenced by export().

                                                        {
    ctools_include('export');

    if (!$identifier) {
      $identifier = $this->db_table;
    }
    $schema = drupal_get_schema($this->db_table);

    $output = $indent . '$' . $identifier . ' = new ' . get_class($this) . ";\n";
    // Go through our schema and build correlations.
    foreach ($schema['fields'] as $field => $info) {
      if (!empty($info['no export'])) {
        continue;
      }
      if (!isset($this->$field)) {
        if (isset($info['default'])) {
          $this->$field = $info['default'];
        }
        else {
          $this->$field = '';
        }

        // serialized defaults must be set as serialized.
        if (isset($info['serialize'])) {
          $this->$field = unserialize(db_decode_blob($this->$field));
        }
      }
      $value = $this->$field;
      if ($info['type'] == 'int') {
        if (isset($info['size']) && $info['size'] == 'tiny') {
          $value = (bool) $value;
        }
        else {
          $value = (int) $value;
        }
      }

      $output .= $indent . '$' . $identifier . '->' . $field . ' = ' . ctools_var_export($value, $indent) . ";\n";
    }
    return $output;
  }

view::fix_missing_relationships (  ) 

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.

Definition at line 558 of file view.inc.

References views_db_object::add_item(), views_fetch_data(), views_move_table(), and views_object_types().

Referenced by init_handlers().

                                       {
    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) {
      $options['table'] = views_move_table($options['table']);
      $data = views_fetch_data($options['table'], FALSE);
      if (isset($data[$options['field']])) {
        $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 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);
        }
      }
    }
  }

views_db_object::generate_display_id ( type  )  [inherited]

Generate a display id of a certain plugin type.

Parameters:
$type Which plugin should be used for the new display id.

Definition at line 2232 of file view.inc.

Referenced by views_db_object::add_display().

                                      {
    // 'default' is singular and is unique, so just go with 'default'
    // for it. For all others, start counting.
    if ($type == 'default') {
      return 'default';
    }
    // Initial id.
    $id = $type . '_1';
    $count = 1;

    // Loop through IDs based upon our style plugin name until
    // we find one that is unused.
    while (!empty($this->display[$id])) {
      $id = $type . '_' . ++$count;
    }

    return $id;
  }

static views_db_object::generate_item_id ( requested_id,
existing_items 
) [static, inherited]

Generates a unique ID for an item.

These items are typically fields, filters, sort criteria, or arguments.

Parameters:
$requested_id The requested ID for the item.
$existing_items An array of existing items, keyed by their IDs.
Returns:
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.

Definition at line 2266 of file view.inc.

Referenced by views_db_object::add_item(), and ViewsUiBaseViewsWizard::alter_display_options().

                                                                          {
    $count = 0;
    $id = $requested_id;
    while (!empty($existing_items[$id])) {
      $id = $requested_id . '_' . ++$count;
    }
    return $id;
  }

view::get_base_tables (  ) 

Create a list of base tables eligible for this view.

Used primarily for the UI. Display must be already initialized.

Definition at line 682 of file view.inc.

                             {
    $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;
  }

view::get_breadcrumb ( set = FALSE  ) 

Get the breadcrumb used for this view.

Parameters:
$set If true, use drupal_set_breadcrumb() to install the breadcrumb.

Definition at line 1560 of file view.inc.

                                        {
    // Now that we've built the view, extract the breadcrumb.
    $base = TRUE;
    $breadcrumb = array();

    if (!empty($this->build_info['breadcrumb'])) {
      foreach ($this->build_info['breadcrumb'] as $path => $title) {
        // Check to see if the frontpage is in the breadcrumb trail; if it
        // is, we'll remove that from the actual breadcrumb later.
        if ($path == variable_get('site_frontpage', 'node')) {
          $base = FALSE;
          $title = t('Home');
        }
        if ($title) {
          $breadcrumb[] = l($title, $path, array('html' => true));
        }
      }

      if ($set) {
        if ($base) {
          $breadcrumb = array_merge(drupal_get_breadcrumb(), $breadcrumb);
        }
        drupal_set_breadcrumb($breadcrumb);
      }
    }
    return $breadcrumb;
  }

view::get_current_page (  ) 

Get the current page from the pager.

Definition at line 308 of file view.inc.

                              {
    if (!empty($this->query->pager)) {
      return $this->query->pager->get_current_page();
    }
  }

view::get_exposed_input (  ) 

Figure out what the exposed input for this view is.

Definition at line 385 of file view.inc.

                               {
    // Fill our input either from $_GET or from something previously set on the
    // view.
    if (empty($this->exposed_input)) {
      $this->exposed_input = $_GET;
      // unset items that are definitely not our input:
      foreach (array('page', 'q') as $key) {
        if (isset($this->exposed_input[$key])) {
          unset($this->exposed_input[$key]);
        }
      }

      // If we have no input at all, check for remembered input via session.

      // 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;

      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;
  }

view::get_human_name (  ) 

Return the human readable name for a view.

When a certain view doesn't have a human readable name return the machine readable name.

Definition at line 1447 of file view.inc.

                            {
    if (!empty($this->human_name)) {
      $human_name = $this->human_name;
    }
    else {
      $human_name = $this->name;
    }
    return $human_name;
  }

views_db_object::get_item ( display_id,
type,
id 
) [inherited]

Get the configuration of an item (field/sort/filter/etc) on a given display.

Definition at line 2364 of file view.inc.

References views_object_types().

Referenced by views_db_object::set_item_option().

                                             {
    // Get info about the types so we can get the right data.
    $types = views_object_types();
    // Initialize the display
    $this->set_display($display_id);

    // Get the existing configuration
    $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);

    return isset($fields[$id]) ? $fields[$id] : NULL;
  }

views_db_object::get_items ( type,
display_id = NULL 
) [inherited]

Get an array of items for the current display.

Definition at line 2348 of file view.inc.

References views_object_types().

                                                {
    $this->set_display($display_id);

    if (!isset($display_id)) {
      $display_id = $this->current_display;
    }

    // Get info about the types so we can get the right data.
    $types = views_object_types();
    return $this->display[$display_id]->handler->get_option($types[$type]['plural']);
  }

view::get_items_per_page (  ) 

Get the items per page from the pager.

Definition at line 317 of file view.inc.

                                {
    if (!empty($this->query->pager)) {
      return $this->query->pager->get_items_per_page();
    }
  }

view::get_offset (  ) 

Get the pager offset from the pager.

Definition at line 338 of file view.inc.

                        {
    if (!empty($this->query->pager)) {
      return $this->query->pager->get_offset();
    }
  }

view::get_path (  ) 

Get the base path used for this view.

Definition at line 1541 of file view.inc.

References set_display().

Referenced by get_url().

                      {
    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();
  }

view::get_title (  ) 

Get the view's current title.

This can change depending upon how it was built.

Definition at line 1410 of file view.inc.

References init_style(), and set_display().

                       {
    if (empty($this->display_handler)) {
      if (!$this->set_display('default')) {
        return FALSE;
      }
    }

    // During building, we might find a title override. If so, use it.
    if (!empty($this->build_info['title'])) {
      $title = $this->build_info['title'];
    }
    else {
      $title = $this->display_handler->get_option('title');
    }

    // Allow substitutions from the first row.
    if ($this->init_style()) {
      $title = $this->style_plugin->tokenize_value($title, 0);
    }
    return $title;
  }

view::get_url ( args = NULL,
path = NULL 
)

Get the URL for the current view.

This URL will be adjusted for arguments.

Definition at line 1477 of file view.inc.

References get_path().

Referenced by _build_arguments().

                                               {
    if (!empty($this->override_url)) {
      return $this->override_url;
    }

    if (!isset($path)) {
      $path = $this->get_path();
    }
    if (!isset($args)) {
      $args = $this->args;

      // Exclude arguments that were computed, not passed on the URL.
      $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++;
        }
      }
    }
    // Don't bother working if there's nothing to do:
    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)) {
          // Try to never put % in a url; use the wildcard instead.
          if ($id && !empty($this->argument[$id]->options['exception']['value'])) {
            $pieces[] = $this->argument[$id]->options['exception']['value'];
          }
          else {
            $pieces[] = '*'; // gotta put something if there just isn't one.
          }

        }
        else {
          $pieces[] = array_shift($args);
        }

        if ($id) {
          $id = next($argument_keys);
        }
      }
    }

    if (!empty($args)) {
      $pieces = array_merge($pieces, $args);
    }
    return implode('/', $pieces);
  }

views_db_object::init ( init = TRUE  )  [inherited]

Initialize this object, setting values from schema defaults.

Parameters:
$init If an array, this is a set of values from db_fetch_object to load. Otherwse, if TRUE values will be filled in from schema defaults.

Definition at line 2027 of file view.inc.

References views_db_object::load_row().

Referenced by __construct().

                              {
    if (is_array($init)) {
      return $this->load_row($init);
    }

    if (!$init) {
      return;
    }

    $schema = drupal_get_schema($this->db_table);

    if (!$schema) {
      return;
    }

    // Go through our schema and build correlations.
    foreach ($schema['fields'] as $field => $info) {
      if ($info['type'] == 'serial') {
        $this->$field = NULL;
      }
      if (!isset($this->$field)) {
        if (!empty($info['serialize']) && isset($info['serialized default'])) {
          $this->$field = unserialize($info['serialized default']);
        }
        elseif (isset($info['default'])) {
          $this->$field = $info['default'];
        }
        else {
          $this->$field = '';
        }
      }
    }
  }

view::init_display ( reset = FALSE  ) 

Set the display for this view and initialize the display handler.

Definition at line 416 of file view.inc.

References views_get_plugin().

Referenced by access(), build_title(), choose_display(), export(), process_locale_strings(), set_display(), and validate().

                                        {
    // The default display is always the first one in the list.
    if (isset($this->current_display)) {
      return TRUE;
    }

    // Instantiate all displays
    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];
        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);
        // 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;
        }
      }
    }

    $this->current_display = 'default';
    $this->display_handler = &$this->display['default']->handler;

    return TRUE;
  }

view::init_handlers (  ) 

Acquire and attach all of the handlers.

Definition at line 642 of file view.inc.

References _init_handler(), fix_missing_relationships(), and views_object_types().

Referenced by build(), and build_title().

                           {
    if (empty($this->inited)) {
      $this->fix_missing_relationships();
      foreach (views_object_types() as $key => $info) {
        $this->_init_handler($key, $info);
      }
      $this->inited = TRUE;
    }
  }

view::init_localization (  ) 

Find and initialize the localizer plugin.

Figure out whether there should be options.

Definition at line 1950 of file view.inc.

References views_get_localization_plugin(), and views_get_plugin().

Referenced by export(), and process_locale_strings().

                               {
    if (isset($this->localization_plugin) && is_object($this->localization_plugin)) {
      return TRUE;
    }

    $this->localization_plugin = views_get_plugin('localization', views_get_localization_plugin());

    if (empty($this->localization_plugin)) {
      return FALSE;
    }

    $this->localization_plugin->init($this);

    return $this->localization_plugin->translate;
  }

view::init_pager (  ) 

Initialize the pager.

Like style initialization, pager initialization is held until late to allow for overrides.

Definition at line 658 of file view.inc.

                        {
    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);
      }

      // 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);
      }
    }
  }

view::init_query (  ) 

Do some common building initialization.

Definition at line 858 of file view.inc.

References views_fetch_data(), and views_get_plugin().

Referenced by build(), build_title(), and export().

                        {
    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'];
    }

    // 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;
  }

view::init_style (  ) 

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.

Definition at line 531 of file view.inc.

References views_get_plugin().

Referenced by build(), get_title(), and render().

                        {
    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;
    }

    // init the new style handler with data.
    $this->style_plugin->init($this, $this->display[$this->current_display], $this->style_options);
    return TRUE;
  }

view::is_cacheable (  ) 

Is this view cacheable?

Definition at line 1591 of file view.inc.

                          {
    return $this->is_cacheable;
  }

view::is_translatable (  ) 

Determine whether a view supports admin string translation.

Definition at line 1972 of file view.inc.

Referenced by process_locale_strings().

                             {
    // If the view is normal or overridden, use admin string translation.
    // A newly created view won't have a type. Accept this.
    return (!isset($this->type) || in_array($this->type, array(t('Normal'), t('Overridden')))) ? TRUE : FALSE;
  }

views_db_object::load_row ( data  )  [inherited]

Load the object with a row from the database.

This method is separate from the constructor in order to give us more flexibility in terms of how the view object is built in different contexts.

Parameters:
$data An object from db_fetch_object. It should contain all of the fields that are in the schema.

Definition at line 2114 of file view.inc.

Referenced by views_db_object::init().

                           {
    $schema = drupal_get_schema($this->db_table);

    // Go through our schema and build correlations.
    foreach ($schema['fields'] as $field => $info) {
      $this->$field = empty($info['serialize']) ? $data->$field : unserialize($data->$field);
    }
  }

static view::load_views (  )  [static]

Static factory method to load a list of views based upon a $where clause.

Although this method could be implemented to simply iterate over views::load(), that would be very slow. Buiding the views externally from unified queries is much faster.

Definition at line 1657 of file view.inc.

References db_objects().

                               {
    $result = db_query("SELECT DISTINCT v.* FROM {views_view} v");
    $views = array();

    // Load all the views.
    foreach ($result as $data) {
      $view = new view;
      $view->load_row($data);
      $view->loaded = TRUE;
      $view->type = t('Normal');
      $views[$view->name] = $view;
      $names[$view->vid] = $view->name;
    }

    // Stop if we didn't get any views.
    if (!$views) {
      return array();
    }

    // Now load all the subtables:
    foreach (view::db_objects() as $key) {
      $object_name = "views_$key";
      $result = db_query("SELECT * FROM {{$object_name}} WHERE vid IN (:vids) ORDER BY vid, position",
        array(':vids' => array_keys($names)));

      foreach ($result as $data) {
        $object = new $object_name(FALSE);
        $object->load_row($data);

        // Because it can get complicated with this much indirection,
        // make a shortcut reference.
        $location = &$views[$names[$object->vid]]->$key;

        // If we have a basic id field, load the item onto the view based on
        // this ID, otherwise push it on.
        if (!empty($object->id)) {
          $location[$object->id] = $object;
        }
        else {
          $location[] = $object;
        }
      }
    }
    return $views;
  }

& views_db_object::new_display ( type = 'page',
title = NULL,
id = NULL 
) [inherited]

Create a new display and a display handler for it.

Parameters:
$type The plugin type from the views plugin data. Defaults to 'page'.
$title The title of the display; optional, may be filled in from default.
$id The id to use.
Returns:
views_plugin_display A reference to the new handler object.

Definition at line 2286 of file view.inc.

References views_db_object::add_display(), and views_get_plugin().

                                                                   {
    $id = $this->add_display($type, $title, $id);

    // Create a handler
    $this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin);
    if (empty($this->display[$id]->handler)) {
      // provide a 'default' handler as an emergency. This won't work well but
      // it will keep things from crashing.
      $this->display[$id]->handler = views_get_plugin('display', 'default');
    }

    if (!empty($this->display[$id]->handler)) {
      // 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
      if ($id != 'default') {
        $this->display[$id]->handler->default_display = &$this->display['default']->handler;
      }
    }

    return $this->display[$id]->handler;
  }

view::post_execute (  ) 

Unset the current view, mostly.

Definition at line 1301 of file view.inc.

References views_set_current_view().

Referenced by execute_display(), and preview().

                          {
    // unset current view so we can be properly destructed later on.
    // Return the previous value in case we're an attachment.

    if ($this->old_view) {
      $old_view = array_pop($this->old_view);
    }

    views_set_current_view(isset($old_view) ? $old_view : FALSE);
  }

view::pre_execute ( args = array()  ) 

Run attachments and let the display do what it needs to do prior to running.

Definition at line 1277 of file view.inc.

References set_arguments(), views_get_current_view(), and views_set_current_view().

Referenced by execute_display(), and preview().

                                        {
    $this->old_view[] = views_get_current_view();
    views_set_current_view($this);
    $display_id = $this->current_display;

    // Prepare the view with the information we have, but only if we were
    // passed arguments, as they may have been set previously.
    if ($args) {
      $this->set_arguments($args);
    }

    // Let modules modify the view just prior to executing it.
    foreach (module_implements('views_pre_view') as $module) {
      $function = $module . '_views_pre_view';
      $function($this, $display_id, $this->args);
    }

    // Allow the display handler to set up for execution
    $this->display_handler->pre_execute();
  }

view::preview ( display_id = NULL,
args = array() 
)

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.

Definition at line 1257 of file view.inc.

References post_execute(), pre_execute(), and set_display().

                                                        {
    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);
    // Preview the view.
    $output = $this->display_handler->preview();

    $this->post_execute();
    return $output;
  }

view::process_locale_strings ( op  ) 

Process strings for localization, deletion or export to code.

Definition at line 2002 of file view.inc.

References init_display(), init_localization(), and is_translatable().

Referenced by delete_locale_strings(), export_locale_strings(), and save_locale_strings().

                                       {
    // Ensure this view supports translation, we have a display, and we
    // have a localization plugin.
    // @fixme Export does not init every handler.
    if (($this->is_translatable() || $op == 'export') && $this->init_display() && $this->init_localization()) {
      $this->localization_plugin->process_locale_strings($op);
    }
  }

view::render ( display_id = NULL  ) 

Render this view for display.

Definition at line 1117 of file view.inc.

References end_query_capture(), execute(), init_style(), and start_query_capture().

                                      {
    $this->execute($display_id);

    // Check to see if the build failed.
    if (!empty($this->build_info['fail'])) {
      return;
    }

    drupal_theme_initialize();

    $start = microtime(TRUE);
    if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) {
      $this->start_query_capture();
    }

    $exposed_form = $this->display_handler->get_plugin('exposed_form');
    $exposed_form->pre_render($this->result);

    // Check for already-cached output.
    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();
      }

      // Run pre_render for the pager as it might change the result.
      if (!empty($this->query->pager)) {
        $this->query->pager->pre_render($this->result);
      }

      // Initialize the style plugin.
      $this->init_style();

      // Give field handlers the opportunity to perform additional queries
      // using the entire resultset prior to rendering.
      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);

      // Let modules modify the view just prior to rendering it.
      foreach (module_implements('views_pre_render') as $module) {
        $function = $module . '_views_pre_render';
        $function($this);
      }

      // Let the theme play too, because pre render is a very themey thing.
      $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');
      }
    }

    $exposed_form->post_render($this->display_handler->output);

    if ($cache) {
      $cache->post_render($this->display_handler->output);
    }

    // Let modules modify the view output after it is rendered.
    foreach (module_implements('views_post_render') as $module) {
      $function = $module . '_views_post_render';
      $function($this, $this->display_handler->output, $cache);
    }

    // Let the theme play too, because post render is a very themey thing.
    $function = $GLOBALS['theme'] . '_views_post_render';
    if (function_exists($function)) {
      $function($this, $this->display_handler->output, $cache);
    }

    if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) {
      $this->end_query_capture();
    }
    $this->render_time = microtime(TRUE) - $start;

    return $this->display_handler->output;
  }

view::render_field ( field,
row 
)

Render a specific field via the field ID and the row #.

Definition at line 1216 of file view.inc.

                                      {
    if (isset($this->field[$field]) && isset($this->result[$row])) {
      return $this->field[$field]->advanced_render($this->result[$row]);
    }
  }

view::save (  ) 

Save the view to the database.

If the view does not already exist, A vid will be assigned to the view and also returned from this function.

Definition at line 1707 of file view.inc.

References _save_rows(), db_objects(), save_locale_strings(), and views_db_object::save_row().

                  {
    if ($this->vid == 'new') {
      $this->vid = NULL;
    }

    // If we have no vid or our vid is a string, this is a new view.
    if (!empty($this->vid)) {
      // remove existing table entries
      foreach ($this->db_objects() as $key) {
        db_delete('views_' . $key)
          ->condition('vid', $this->vid)
          ->execute();
      }
    }

    $this->save_row(!empty($this->vid) ? 'vid' : FALSE);

    // Save all of our subtables.
    foreach ($this->db_objects() as $key) {
      $this->_save_rows($key);
    }

    $this->save_locale_strings();

    cache_clear_all('views_urls', 'cache_views');
    cache_clear_all(); // clear the page cache as well.
  }

view::save_locale_strings (  ) 

Send strings for localization.

Definition at line 1981 of file view.inc.

References process_locale_strings().

Referenced by save().

                                 {
    $this->process_locale_strings('save');
  }

views_db_object::save_row ( update = NULL  )  [inherited]

Write the row to the database.

Parameters:
$update If true this will be an UPDATE query. Otherwise it will be an INSERT.

Definition at line 2067 of file view.inc.

Referenced by save().

                                    {
    $fields = $defs = $values = $serials = array();
    $schema = drupal_get_schema($this->db_table);

    // Go through our schema and build correlations.
    foreach ($schema['fields'] as $field => $info) {
      // special case -- skip serial types if we are updating.
      if ($info['type'] == 'serial') {
        $serials[] = $field;
        continue;
      }
      elseif ($info['type'] == 'int') {
        $this->$field = (int) $this->$field;
      }
      $fields[$field] = empty($info['serialize']) ? $this->$field : serialize($this->$field);
    }
    if (!$update) {
      $query = db_insert($this->db_table);
    }
    else {
      $query = db_update($this->db_table)
        ->condition($update, $this->$update);
    }
    $return = $query
      ->fields($fields)
      ->execute();

    if ($serials && !$update) {
      // get last insert ids and fill them in.
      // Well, one ID.
      foreach ($serials as $field) {
        $this->$field = $return;
      }
    }
  }

view::set_arguments ( args  ) 

Set the arguments that come to this view.

Usually from the URL but possibly from elsewhere.

Definition at line 294 of file view.inc.

Referenced by pre_execute().

                                {
    $this->args = $args;
  }

view::set_current_page ( page  ) 

Change/Set the current page for the pager.

Definition at line 301 of file view.inc.

                                   {
    $this->current_page = $page;
  }

view::set_display ( display_id = NULL  ) 

Set the display as current.

Parameters:
$display_id The id of the display to mark as current.

Definition at line 483 of file view.inc.

References choose_display(), init_display(), and vpr().

Referenced by build(), execute_display(), execute_hook_block_list(), execute_hook_menu(), get_path(), get_title(), preview(), and validate().

                                           {
    // 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)) {
      return FALSE;
    }

    // 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));
        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;
    }

    // Set a shortcut
    $this->display_handler = &$this->display[$display_id]->handler;

    return TRUE;
  }

view::set_exposed_input ( filters  ) 

Set the exposed filters input to an array.

If unset they will be taken from $_GET when the time comes.

Definition at line 378 of file view.inc.

                                       {
    $this->exposed_input = $filters;
  }

views_db_object::set_item ( display_id,
type,
id,
item 
) [inherited]

Set the configuration of an item (field/sort/filter/etc) on a given display.

Pass in NULL for the $item to remove an item.

Definition at line 2382 of file view.inc.

References views_object_types().

Referenced by views_db_object::set_item_option().

                                                    {
    // Get info about the types so we can get the right data.
    $types = views_object_types();
    // Initialize the display
    $this->set_display($display_id);

    // Get the existing configuration
    $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
    if (isset($item)) {
      $fields[$id] = $item;
    }
    else {
      unset($fields[$id]);
    }

    // Store.
    $this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
  }

views_db_object::set_item_option ( display_id,
type,
id,
option,
value 
) [inherited]

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.

Definition at line 2408 of file view.inc.

References views_db_object::get_item(), and views_db_object::set_item().

                                                                     {
    $item = $this->get_item($display_id, $type, $id);
    $item[$option] = $value;
    $this->set_item($display_id, $type, $id, $item);
  }

view::set_items_per_page ( items_per_page  ) 

Set the items per page on the pager.

Definition at line 326 of file view.inc.

                                               {
    $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);
    }
  }

view::set_offset ( offset  ) 

Set the offset on the pager.

Definition at line 347 of file view.inc.

                               {
    $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);
    }
  }

view::set_title ( title  ) 

Override the view's current title.

The tokens in the title get's replaced before rendering.

Definition at line 1437 of file view.inc.

                             {
     $this->build_info['title'] = $title;
     return TRUE;
   }

view::set_use_ajax ( use_ajax  ) 

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.

Definition at line 370 of file view.inc.

                                   {
    $this->use_ajax = $use_ajax;
  }

view::start_query_capture (  ) 

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.

Definition at line 1604 of file view.inc.

Referenced by render().

                                 {
    global $conf, $queries;
    if (empty($conf['dev_query'])) {
      $this->fix_dev_query = TRUE;
      $conf['dev_query'] = TRUE;
    }

    // Record the last query key used; anything already run isn't
    // a query that we are interested in.
    $this->last_query_key = NULL;

    if (!empty($queries)) {
      $keys = array_keys($queries);
      $this->last_query_key = array_pop($keys);
    }
  }

view::update (  ) 

Perform automatic updates when loading or importing a view.

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.

Definition at line 267 of file view.inc.

References views_move_table().

                    {
    // 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);
  }

view::use_pager (  ) 

Determine if the pager actually uses a pager.

Definition at line 359 of file view.inc.

                       {
    if (!empty($this->query->pager)) {
      return $this->query->pager->use_pager();
    }
  }

view::validate (  ) 

Make sure the view is completely valid.

Returns:
TRUE if the view is valid; an array of error strings if it is not.

Definition at line 1924 of file view.inc.

References init_display(), and set_display().

                      {
    $this->init_display();

    $errors = array();

    $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->set_display($current_display);
    return $errors ? $errors : TRUE;
  }


Member Data Documentation

view::$base_database = NULL

Allow to override the used database which is used for this query.

Definition at line 195 of file view.inc.


The documentation for this class was generated from the following file: