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

Inheritance diagram for view:

views_db_object List of all members.

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 19 of file view.inc.

Public Member Functions

 view ()
 Constructor.
 display_objects ()
 Returns a list of the sub-object types used by this view.
 db_objects ()
 Returns the complete list of dependent objects in a view, for the purpose of initialization and loading/saving to/from the database.
 set_arguments ($args)
 Set the arguments that come to this view.
 set_items_per_page ($items_per_page)
 Set the page size for ranged or pager queries.
 set_current_page ($page)
 Change/Set the current page for the pager.
 set_use_pager ($use_pager)
 Whether or not the pager should be used.
 set_pager_element ($pager_element)
 The pager element id to use if use_apger is on.
 set_offset ($offset)
 How many records to skip.
 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.
 init_handlers ()
 Acquire and attach all of the handlers.
 get_base_tables ()
 Create a list of base tables eligible for this view.
 _pre_query ()
 Run the pre_query() on all active handlers.
 _init_handler ($key, $info)
 Attach all of the handlers for each type.
 render_exposed_form ($block=FALSE)
 Render the exposed filter form.
 _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)
 Called to get hook_menu information from the view and the named display handler.
 execute_hook_block ($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.
 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.
load ($arg, $reset=FALSE)
 Load a view from the database based upon either vid or name.
 load_views ()
 Static factory method to load a list of views based upon a $where clause.
 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 ()
 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 ($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.
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)
 Get 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.

Public Attributes

 $db_table = 'views_view'
 $base_table = 'node'
 $built = FALSE
 $executed = FALSE
 $args = array()
 $build_info = array()
 $use_ajax = FALSE
 $result = array()
 $pager
 $attachment_before = ''
 $attachment_after = ''
 $exposed_data = array()
 $exposed_input = array()
 $old_view = array()


Member Function Documentation

view::_build ( key  ) 

Internal method to build an individual set of handlers.

Definition at line 657 of file view.inc.

Referenced by build().

00657                         {
00658     $handlers = &$this->$key;
00659     foreach ($handlers as $id => $data) {
00660       if (!empty($handlers[$id]) && is_object($handlers[$id])) {
00661         // Give this handler access to the exposed filter input.
00662         if (!empty($this->exposed_data)) {
00663           $rc = $handlers[$id]->accept_exposed_input($this->exposed_data);
00664           $handlers[$id]->store_exposed_input($this->exposed_data, $rc);
00665           if (!$rc) {
00666             continue;
00667           }
00668         }
00669         $handlers[$id]->set_relationship();
00670         $handlers[$id]->query();
00671       }
00672     }
00673   }

view::_build_arguments (  ) 

Build all the arguments.

Definition at line 424 of file view.inc.

References $title, and get_url().

Referenced by build(), and build_title().

00424                               {
00425     // Initially, we want to build sorts and fields. This can change, though,
00426     // if we get a summary view.
00427     if (empty($this->argument)) {
00428       return TRUE;
00429     }
00430 
00431     // build arguments.
00432     $position = -1;
00433 
00434     // Create a title for use in the breadcrumb trail.
00435     $title = $this->display_handler->get_option('title');
00436 
00437     $this->build_info['breadcrumb'] = array();
00438     $breadcrumb_args = array();
00439     $substitutions = array();
00440 
00441     $status = TRUE;
00442 
00443     // Iterate through each argument and process.
00444     foreach ($this->argument as $id => $arg) {
00445       $position++;
00446       $argument = &$this->argument[$id];
00447 
00448       if ($argument->broken()) {
00449         continue;
00450       }
00451 
00452       $argument->set_relationship();
00453 
00454       $arg = isset($this->args[$position]) ? $this->args[$position] : NULL;
00455       $argument->position = $position;
00456 
00457       if (isset($arg) || $argument->has_default_argument()) {
00458         if (!isset($arg)) {
00459           $arg = $argument->get_default_argument();
00460           // make sure default args get put back.
00461           if (isset($arg)) {
00462             $this->args[$position] = $arg;
00463           }
00464         }
00465 
00466         // Set the argument, which will also validate that the argument can be set.
00467         if (!$argument->set_argument($arg)) {
00468           $status = $argument->validate_fail($arg);
00469           break;
00470         }
00471 
00472         if ($argument->is_wildcard()) {
00473           $arg_title = $argument->wildcard_title();
00474         }
00475         else {
00476           $arg_title = $argument->get_title();
00477           $argument->query();
00478         }
00479 
00480         // Add this argument's substitution
00481         $substitutions['%' . ($position + 1)] = $arg_title;
00482 
00483         // Since we're really generating the breadcrumb for the item above us,
00484         // check the default action of this argument.
00485         if ($this->display_handler->uses_breadcrumb() && $argument->uses_breadcrumb()) {
00486           $path = $this->get_url($breadcrumb_args);
00487           if (strpos($path, '%') === FALSE) {
00488             $breadcrumb = !empty($argument->options['breadcrumb'])? $argument->options['breadcrumb'] : $title;
00489             $this->build_info['breadcrumb'][$path] = str_replace(array_keys($substitutions), $substitutions, $breadcrumb);
00490           }
00491         }
00492 
00493         // Allow the argument to muck with this breadcrumb.
00494         $argument->set_breadcrumb($this->build_info['breadcrumb']);
00495 
00496         // Test to see if we should use this argument's title
00497         if (!empty($argument->options['title'])) {
00498           $title = $argument->options['title'];
00499         }
00500 
00501         $breadcrumb_args[] = $arg;
00502       }
00503       else {
00504         // determine default condition and handle.
00505         $status = $argument->default_action();
00506         break;
00507       }
00508 
00509       // Be safe with references and loops:
00510       unset($argument);
00511     }
00512 
00513     // set the title in the build info.
00514     if (!empty($title)) {
00515       $this->build_info['title'] = str_replace(array_keys($substitutions), $substitutions, $title);
00516     }
00517 
00518     // Store the arguments for later use.
00519     $this->build_info['substitutions'] = $substitutions;
00520 
00521     return $status;
00522   }

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 370 of file view.inc.

References access().

Referenced by init_handlers().

00370                                       {
00371     // Load the requested items from the display onto the object.
00372     $this->$key = $this->display_handler->get_handlers($key);
00373 
00374     // This reference deals with difficult PHP indirection.
00375     $handlers = &$this->$key;
00376 
00377     // Run through and test for accessibility.
00378     foreach ($handlers as $id => $handler) {
00379       if (!$handler->access()) {
00380         unset($handlers[$id]);
00381       }
00382     }
00383   }

view::_pre_query (  ) 

Run the pre_query() on all active handlers.

Definition at line 350 of file view.inc.

References views_object_types().

Referenced by build().

00350                         {
00351     foreach (views_object_types() as $key => $info) {
00352       $handlers = &$this->$key;
00353       $position = 0;
00354       foreach ($handlers as $id => $handler) {
00355         $handlers[$id]->position = $position;
00356         $handlers[$id]->pre_query();
00357         $position++;
00358       }
00359     }
00360   }

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 1414 of file view.inc.

Referenced by save().

01414                             {
01415     $count = 0;
01416     foreach ($this->$key as $position => $object) {
01417       $object->position = ++$count;
01418       $object->vid = $this->vid;
01419       $object->save_row();
01420     }
01421   }

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 1048 of file view.inc.

References $display_id, and init_display().

Referenced by _init_handler().

01048                                                      {
01049     if (!isset($this->current_display)) {
01050       $this->init_display();
01051     }
01052 
01053     if (!$account) {
01054       $account = $GLOBALS['user'];
01055     }
01056 
01057     // We can't use choose_display() here because that function
01058     // calls this one.
01059     $displays = (array)$displays;
01060     foreach ($displays as $display_id) {
01061       if (!empty($this->display[$display_id]->handler)) {
01062         if ($this->display[$display_id]->handler->access($account)) {
01063           return TRUE;
01064         }
01065       }
01066     }
01067 
01068     return FALSE;
01069   }

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 1795 of file view.inc.

References $title.

Referenced by views_db_object::new_display().

01795                                                                   {
01796     if (empty($type)) {
01797       return FALSE;
01798     }
01799 
01800     $plugin = views_fetch_plugin_data('display', $type);
01801     if (empty($plugin)) {
01802       $plugin['title'] = t('Broken');
01803     }
01804 
01805     // 'default' is singular and is unique, so just go with 'default'
01806     // for it. For all others, start counting.
01807     if (empty($id)) {
01808       $id = ($type == 'default') ? $type : $type . '_1';
01809       $title = $plugin['title'];
01810 
01811       $count = 1;
01812 
01813       // Loop through IDs based upon our style plugin name until
01814       // we find one that is unused.
01815       while (!empty($this->display[$id])) {
01816         $id = $type . '_' . ++$count;
01817         if (empty($title)) {
01818           $title = $plugin['title'] . ' ' . $count;
01819         }
01820       }
01821     }
01822 
01823     // Create the new display object
01824     $display = new views_display;
01825     $display->options($type, $id, $title);
01826 
01827     // Add the new display object to the view.
01828     $this->display[$id] = $display;
01829     return $id;
01830   }

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 1871 of file view.inc.

References $display_id, $field, and views_object_types().

01871                                                                                         {
01872     $types = views_object_types();
01873     $this->set_display($display_id);
01874 
01875     $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
01876 
01877     if (empty($id)) {
01878       $count = 0;
01879       $id = $field;
01880       while (!empty($fields[$id])) {
01881         $id = $field . '_' . ++$count;
01882       }
01883     }
01884 
01885     $new_item = array(
01886       'id' => $id,
01887       'table' => $table,
01888       'field' => $field,
01889     ) + $options;
01890 
01891     $handler = views_get_handler($table, $field, $type);
01892 
01893     $fields[$id] = $new_item;
01894     $this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
01895 
01896     return $id;
01897   }

view::attach_displays (  ) 

Run attachment displays for the view.

Definition at line 989 of file view.inc.

Referenced by build().

00989                              {
00990     if (!empty($this->is_attachment)) {
00991       return;
00992     }
00993 
00994     if (!$this->display_handler->accept_attachments()) {
00995       return;
00996     }
00997 
00998     $this->is_attachment = TRUE;
00999     // Give other displays an opportunity to attach to the view.
01000     foreach ($this->display as $id => $display) {
01001       if (!empty($this->display[$id]->handler)) {
01002         $this->display[$id]->handler->attach_to($this->current_display);
01003       }
01004     }
01005     $this->is_attachment = FALSE;
01006   }

view::build ( display_id = NULL  ) 

Build the query for the view.

Definition at line 541 of file view.inc.

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

Referenced by execute().

00541                                      {
00542     if (!empty($this->built)) {
00543       return;
00544     }
00545 
00546     if (empty($this->current_display) || $display_id) {
00547       if (!$this->set_display($display_id)) {
00548         return FALSE;
00549       }
00550     }
00551 
00552     // Let modules modify the view just prior to executing it.
00553     foreach (module_implements('views_pre_build') as $module) {
00554       $function = $module . '_views_pre_build';
00555       $function($this);
00556     }
00557 
00558     // Attempt to load from cache.
00559     // @todo Load a build_info from cache.
00560 
00561     $start = views_microtime();
00562     // If that fails, let's build!
00563     $this->build_info = array(
00564       'query' => '',
00565       'count_query' => '',
00566       'query_args' => array(),
00567     );
00568 
00569     $this->init_query();
00570 
00571     // Call a module hook and see if it wants to present us with a
00572     // pre-built query or instruct us not to build the query for
00573     // some reason.
00574     // @todo: Implement this. Use the same mechanism Panels uses.
00575 
00576     // Run through our handlers and ensure they have necessary information.
00577     $this->init_handlers();
00578 
00579     // Let the handlers interact with each other if they really want.
00580     $this->_pre_query();
00581 
00582     if ($this->display_handler->uses_exposed()) {
00583       $this->exposed_widgets = $this->render_exposed_form();
00584       if (form_set_error() || !empty($this->build_info['abort'])) {
00585         $this->built = TRUE;
00586         return empty($this->build_info['fail']);
00587       }
00588     }
00589 
00590     // Build all the relationships first thing.
00591     $this->_build('relationship');
00592 
00593     // Build all the filters.
00594     $this->_build('filter');
00595 
00596     $this->build_sort = TRUE;
00597 
00598     // Arguments can, in fact, cause this whole thing to abort.
00599     if (!$this->_build_arguments()) {
00600       $this->build_time = views_microtime() - $start;
00601       $this->attach_displays();
00602       return $this->built;
00603     }
00604 
00605     // Initialize the style; arguments may have changed which style we use,
00606     // so waiting as long as possible is important. But we need to know
00607     // about the style when we go to build fields.
00608     if (!$this->init_style()) {
00609       $this->build_info['fail'] = TRUE;
00610       return FALSE;
00611     }
00612 
00613     if ($this->style_plugin->uses_fields()) {
00614       $this->_build('field');
00615     }
00616 
00617     // Build our sort criteria if we were instructed to do so.
00618     if (!empty($this->build_sort)) {
00619       // Allow the style handler to deal with sorting.
00620       if ($this->style_plugin->build_sort()) {
00621         $this->_build('sort');
00622       }
00623       // allow the plugin to build second sorts as well.
00624       $this->style_plugin->build_sort_post();
00625     }
00626 
00627     // Allow display handler to affect the query:
00628     $this->display_handler->query();
00629 
00630     // Allow style handler to affect the query:
00631     $this->style_plugin->query();
00632 
00633     if (variable_get('views_sql_signature', FALSE)) {
00634       $this->query->add_field(NULL, "'" . $this->name . ':' . $this->current_display . "'", 'view_name');
00635     }
00636 
00637     // Let modules modify the query just prior to finalizing it.
00638     foreach (module_implements('views_query_alter') as $module) {
00639       $function = $module . '_views_query_alter';
00640       $function($this, $this->query);
00641     }
00642 
00643     $this->build_info['query'] = $this->query->query();
00644     $this->build_info['count_query'] = $this->query->query(TRUE);
00645     $this->build_info['query_args'] = $this->query->get_where_args();
00646     $this->built = TRUE;
00647     $this->build_time = views_microtime() - $start;
00648 
00649     // Attach displays
00650     $this->attach_displays();
00651     return TRUE;
00652   }

view::build_title (  ) 

Force the view to build a title.

Definition at line 1096 of file view.inc.

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

01096                          {
01097     $this->init_display();
01098     if (empty($this->built)) {
01099       $this->init_query();
01100     }
01101     $this->init_handlers();
01102 
01103     $this->_build_arguments();
01104   }

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 228 of file view.inc.

References $display_id, and init_display().

Referenced by execute_display(), and set_display().

00228                                      {
00229     if (!is_array($displays)) {
00230       return $displays;
00231     }
00232 
00233     $this->init_display();
00234 
00235     foreach ($displays as $display_id) {
00236       if ($this->display[$display_id]->handler->access()) {
00237         return $display_id;
00238       }
00239     }
00240 
00241     return 'default';
00242   }

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.

Definition at line 1512 of file view.inc.

01512                         {
01513     $clone = version_compare(phpversion(), '5.0') < 0 ? $this : clone($this);
01514 
01515     $keys = array('current_display', 'display_handler', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables');
01516     foreach ($keys as $key) {
01517       if (isset($clone->$key)) {
01518         unset($clone->$key);
01519       }
01520     }
01521     $clone->built = $clone->executed = FALSE;
01522     $clone->build_info = array();
01523     $clone->attachment_before = '';
01524     $clone->attachment_after = '';
01525     $clone->result = array();
01526 
01527     // shallow cloning means that all the display objects
01528     // *were not cloned*. We must clone them ourselves.
01529     $displays = array();
01530     foreach ($clone->display as $id => $display) {
01531       $displays[$id] = drupal_clone($display);
01532       if (isset($displays[$id]->handler)) {
01533         unset($displays[$id]->handler);
01534       }
01535     }
01536     $clone->display = $displays;
01537 
01538     return $clone;
01539   }

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 1495 of file view.inc.

References export().

01495                   {
01496     $code = $this->export();
01497     eval($code);
01498     return $view;
01499   }

view::db_objects (  ) 

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

Note: In PHP5 this should be static, but PHP4 doesn't support static methods.

Definition at line 82 of file view.inc.

Referenced by delete(), load(), load_views(), save(), and view().

00082                         {
00083     return array('display');
00084   }

view::delete (  ) 

Delete the view from the database.

Definition at line 1426 of file view.inc.

References db_objects().

01426                     {
01427     if (empty($this->vid)) {
01428       return;
01429     }
01430 
01431     db_query("DELETE FROM {views_view} WHERE vid = %d", $this->vid);
01432     // Delete from all of our subtables as well.
01433     foreach ($this->db_objects() as $key) {
01434       db_query("DELETE from {views_" . $key . "} WHERE vid = %d", $this->vid);
01435     }
01436 
01437     cache_clear_all('views_query:' . $this->name, 'cache_views');
01438     cache_clear_all(); // In Drupal 5.0 and later this clears the page cache only.
01439     menu_rebuild(); // force a menu rebuild when a view is deleted.
01440   }

view::destroy (  ) 

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

Definition at line 1545 of file view.inc.

References $display_id, $item, and views_object_types().

01545                      {
01546     foreach (array_keys($this->display) as $display_id) {
01547       if (isset($this->display[$display_id]->handler)) {
01548         $this->display[$display_id]->handler->destroy();
01549         unset($this->display[$display_id]->handler);
01550       }
01551 
01552       foreach (views_object_types() as $type => $info) {
01553         if (isset($this->$type)) {
01554           $handlers = &$this->$type;
01555           foreach ($handlers as $id => $item) {
01556             $handlers[$id]->destroy();
01557           }
01558           unset($handlers);
01559         }
01560       }
01561 
01562       if (isset($this->style_plugin)) {
01563         $this->style_plugin->destroy();
01564         unset($this->style_plugin);
01565       }
01566 
01567       // Clear these to make sure the view can be processed/used again.
01568       if (isset($this->display_handler)) {
01569         unset($this->display_handler);
01570       }
01571 
01572       if (isset($this->current_display)) {
01573         unset($this->current_display);
01574       }
01575 
01576       if (isset($this->query)) {
01577         unset($this->query);
01578       }
01579     }
01580   }

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 71 of file view.inc.

00071                              {
00072     return array('argument', 'field', 'sort', 'filter', 'relationship');
00073   }

view::end_query_capture (  ) 

Add the list of queries run during render to buildinfo.

See also:
view::start_query_capture()

Definition at line 1246 of file view.inc.

Referenced by render().

01246                                {
01247     global $conf, $queries;
01248     if (!empty($this->fix_dev_query)) {
01249       $conf['dev_query'] = FALSE;
01250     }
01251 
01252     // make a copy of the array so we can manipulate it with array_splice.
01253     $temp = $queries;
01254 
01255     // Scroll through the queries until we get to our last query key.
01256     // Unset anything in our temp array.
01257     if (isset($this->last_query_key)) {
01258       while (list($id, $query) = each($queries)) {
01259         if ($id == $this->last_query_key) {
01260           break;
01261         }
01262 
01263         unset($temp[$id]);
01264       }
01265     }
01266 
01267     $this->additional_queries = $temp;
01268   }

view::execute ( display_id = NULL  ) 

Execute the view's query.

Definition at line 678 of file view.inc.

References $args, $display_id, $item, $items, $result, and build().

Referenced by render().

00678                                        {
00679     if (empty($this->built)) {
00680       if (!$this->build($display_id)) {
00681         return FALSE;
00682       }
00683     }
00684 
00685     if (!empty($this->executed)) {
00686       return TRUE;
00687     }
00688 
00689     // Let modules modify the view just prior to executing it.
00690     foreach (module_implements('views_pre_execute') as $module) {
00691       $function = $module . '_views_pre_execute';
00692       $function($this);
00693     }
00694 
00695     $query = db_rewrite_sql($this->build_info['query'], $this->base_table, $this->base_field, array('view' => &$this));
00696     $count_query = db_rewrite_sql($this->build_info['count_query'], $this->base_table, $this->base_field, array('view' => &$this));
00697 
00698     $args = $this->build_info['query_args'];
00699 
00700     vpr($query);
00701 
00702 
00703     // Check for already-cached results.
00704     if (!empty($this->live_preview)) {
00705       $cache = FALSE;
00706     }
00707     else {
00708       $cache = $this->display_handler->get_cache_plugin();
00709     }
00710     if ($cache && $cache->cache_get('results')) {
00711       vpr('Used cached results');
00712     }
00713     else {
00714       $items = array();
00715       if ($query) {
00716         $replacements = module_invoke_all('views_query_substitutions', $this);
00717         $query = str_replace(array_keys($replacements), $replacements, $query);
00718         $count_query = 'SELECT COUNT(*) FROM (' . str_replace(array_keys($replacements), $replacements, $count_query) . ') count_alias';
00719 
00720         if (is_array($args)) {
00721           foreach ($args as $id => $arg) {
00722             $args[$id] = str_replace(array_keys($replacements), $replacements, $arg);
00723           }
00724         }
00725 
00726         // Allow for a view to query an external database.
00727         if (isset($this->base_database)) {
00728           db_set_active($this->base_database);
00729           $external = TRUE;
00730         }
00731 
00732         $start = views_microtime();
00733         if (!empty($this->pager['items_per_page'])) {
00734           // We no longer use pager_query() here because pager_query() does not
00735           // support an offset. This is fine as we don't actually need pager
00736           // query; we've already been doing most of what it does, and we
00737           // just need to do a little more playing with globals.
00738           if (!empty($this->pager['use_pager']) || !empty($this->get_total_rows)) {
00739             $this->total_rows = db_result(db_query($count_query, $args)) - $this->pager['offset'];
00740           }
00741 
00742           if (!empty($this->pager['use_pager'])) {
00743             // dump information about what we already know into the globals
00744             global $pager_page_array, $pager_total, $pager_total_items;
00745             // total rows in query
00746             $pager_total_items[$this->pager['element']] = $this->total_rows;
00747             // total pages
00748             $pager_total[$this->pager['element']] = ceil($pager_total_items[$this->pager['element']] / $this->pager['items_per_page']);
00749 
00750             // What page was requested:
00751             $pager_page_array = isset($_GET['page']) ? explode(',', $_GET['page']) : array();
00752 
00753             // If the requested page was within range. $this->pager['current_page']
00754             // defaults to 0 so we don't need to set it in an out-of-range condition.
00755             if (!empty($pager_page_array[$this->pager['element']])) {
00756               $page = intval($pager_page_array[$this->pager['element']]);
00757               if ($page > 0 && $page < $pager_total[$this->pager['element']]) {
00758                 $this->pager['current_page'] = $page;
00759               }
00760             }
00761             $pager_page_array[$this->pager['element']] = $this->pager['current_page'];
00762           }
00763 
00764           $offset = $this->pager['current_page'] * $this->pager['items_per_page'] + $this->pager['offset'];
00765           $result = db_query_range($query, $args, $offset, $this->pager['items_per_page']);
00766 
00767         }
00768         else {
00769           $result = db_query($query, $args);
00770         }
00771 
00772         $this->result = array();
00773         while ($item = db_fetch_object($result)) {
00774           $this->result[] = $item;
00775         }
00776 
00777         // If we already know how many items we have even if we did not run the
00778         // count query, go ahead and set that value:
00779         if (empty($this->pager['items_per_page'])) {
00780           $this->total_rows = count($this->result);
00781         }
00782 
00783         if (!empty($external)) {
00784           db_set_active();
00785         }
00786         $this->execute_time = views_microtime() - $start;
00787       }
00788       if ($cache) {
00789         $cache->cache_set('results');
00790       }
00791     }
00792 
00793     $this->executed = TRUE;
00794   }

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 906 of file view.inc.

References $args, $display_id, choose_display(), post_execute(), pre_execute(), and set_display().

00906                                                                 {
00907     if (empty($this->current_display) || $this->current_display != $this->choose_display($display_id)) {
00908       if (!$this->set_display($display_id)) {
00909         return FALSE;
00910       }
00911     }
00912 
00913     $this->pre_execute($args);
00914 
00915     // Execute the view
00916     $output = $this->display_handler->execute();
00917 
00918     $this->post_execute();
00919     return $output;
00920   }

view::execute_hook_block ( display_id = NULL  ) 

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

Definition at line 1030 of file view.inc.

References $display_id, and set_display().

01030                                                   {
01031     // Prepare the view with the information we have.
01032 
01033     // This was probably already called, but it's good to be safe.
01034     if (!$this->set_display($display_id)) {
01035       return FALSE;
01036     }
01037 
01038     // Execute the view
01039     if (isset($this->display_handler)) {
01040       return $this->display_handler->execute_hook_block();
01041     }
01042   }

view::execute_hook_menu ( display_id = NULL  ) 

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

Definition at line 1012 of file view.inc.

References $display_id, and set_display().

01012                                                  {
01013     // Prepare the view with the information we have.
01014 
01015     // This was probably already called, but it's good to be safe.
01016     if (!$this->set_display($display_id)) {
01017       return FALSE;
01018     }
01019 
01020     // Execute the view
01021     if (isset($this->display_handler)) {
01022       return $this->display_handler->execute_hook_menu();
01023     }
01024   }

view::export ( indent = ''  ) 

Export a view as PHP code.

Definition at line 1445 of file view.inc.

References views_db_object::export_row(), and init_display().

Referenced by copy().

01445                                 {
01446     $this->init_display();
01447     $output = '';
01448     $output .= $this->export_row('view', $indent);
01449     // Set the API version
01450     $output .= $indent . '$view->api_version = 2' . ";\n";
01451     $output .= $indent . '$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */' . "\n";
01452 
01453     foreach ($this->display as $id => $display) {
01454       $output .= $indent . '$handler = $view->new_display(' . views_var_export($display->display_plugin, $indent) . ', ' . views_var_export($display->display_title, $indent) . ', \'' . $id . "');\n";
01455       if (empty($display->handler)) {
01456         // @todo -- probably need a method of exporting broken displays as
01457         // they may simply be broken because a module is not installed. That
01458         // does not invalidate the display.
01459         continue;
01460       }
01461 
01462       foreach ($display->handler->option_definition() as $option => $definition) {
01463         // Special handling for some items
01464         switch ($option) {
01465           case 'defaults':
01466             // skip these
01467             break;
01468           default:
01469             if (!$display->handler->is_defaulted($option)) {
01470               $value = $display->handler->get_option($option);
01471               if ($id == 'default') {
01472                 $default = isset($definition['default']) ? $definition['default'] : NULL;
01473               }
01474               else {
01475                 $default = $this->display['default']->handler->get_option($option);
01476               }
01477 
01478               if ($value !== $default) {
01479                 $output .= $indent . '$handler->override_option(\'' . $option . '\', ' . views_var_export($value, $indent) . ");\n";
01480               }
01481             }
01482         }
01483       }
01484     }
01485 
01486     return $output;
01487   }

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 1747 of file view.inc.

References $field.

Referenced by export().

01747                                                         {
01748     if (!$identifier) {
01749       $identifier = $this->db_table;
01750     }
01751     $schema = drupal_get_schema($this->db_table);
01752 
01753     $output = $indent . '$' . $identifier . ' = new ' . get_class($this) . ";\n";
01754     // Go through our schema and build correlations.
01755     foreach ($schema['fields'] as $field => $info) {
01756       if (!empty($info['no export'])) {
01757         continue;
01758       }
01759       if (!isset($this->$field)) {
01760         if (isset($info['default'])) {
01761           $this->$field = $info['default'];
01762         }
01763         else {
01764           $this->$field = '';
01765         }
01766 
01767         // serialized defaults must be set as serialized.
01768         if (isset($info['serialize'])) {
01769           $this->$field = unserialize(db_decode_blob($this->$field));
01770         }
01771       }
01772       $value = $this->$field;
01773       if ($info['type'] == 'int') {
01774         $value = ($info['size'] == 'tiny') ? (bool) $value : (int) $value;
01775       }
01776 
01777       $output .= $indent . '$' . $identifier . '->' . $field . ' = ' . views_var_export($value, $indent) . ";\n";
01778     }
01779     return $output;
01780   }

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 335 of file view.inc.

00335                              {
00336     $base_tables = array(
00337       $this->base_table => TRUE,
00338       '#global' => TRUE,
00339     );
00340 
00341     foreach ($this->display_handler->get_handlers('relationship') as $handler) {
00342       $base_tables[$handler->definition['base']] = TRUE;
00343     }
00344     return $base_tables;
00345   }

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 1180 of file view.inc.

References $title.

01180                                         {
01181     // Now that we've built the view, extract the breadcrumb.
01182     $base = TRUE;
01183     $breadcrumb = array();
01184 
01185     if (!empty($this->build_info['breadcrumb'])) {
01186       foreach ($this->build_info['breadcrumb'] as $path => $title) {
01187         // Check to see if the frontpage is in the breadcrumb trail; if it
01188         // is, we'll remove that from the actual breadcrumb later.
01189         if ($path == variable_get('site_frontpage', 'node')) {
01190           $base = FALSE;
01191           $title = t('Home');
01192         }
01193         if ($title) {
01194           $breadcrumb[] = l($title, $path, array('html' => true));
01195         }
01196       }
01197 
01198       if ($set) {
01199         if ($base) {
01200           $breadcrumb = array_merge(drupal_get_breadcrumb(), $breadcrumb);
01201         }
01202         drupal_set_breadcrumb($breadcrumb);
01203       }
01204     }
01205     return $breadcrumb;
01206   }

view::get_exposed_input (  ) 

Figure out what the exposed input for this view is.

Definition at line 153 of file view.inc.

References $display_id.

00153                                {
00154     // Fill our input either from $_GET or from something previously set on the
00155     // view.
00156     if (empty($this->exposed_input)) {
00157       $this->exposed_input = $_GET;
00158       // unset items that are definitely not our input:
00159       foreach (array('page', 'q') as $key) {
00160         if (isset($this->exposed_input[$key])) {
00161           unset($this->exposed_input[$key]);
00162         }
00163       }
00164 
00165       // If we have no input at all, check for remembered input via session.
00166 
00167       // If filters are not overridden, store the 'remember' settings on the
00168       // default display. If they are, store them on this display. This way,
00169       // multiple displays in the same view can share the same filters and
00170       // remember settings.
00171       $display_id = ($this->display_handler->is_defaulted('filters')) ? 'default' : $this->current_display;
00172 
00173       if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->name][$display_id])) {
00174         $this->exposed_input = $_SESSION['views'][$this->name][$display_id];
00175       }
00176     }
00177 
00178     return $this->exposed_input;
00179   }

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 1918 of file view.inc.

References $display_id, and views_object_types().

Referenced by views_db_object::set_item_option().

01918                                              {
01919     // Get info about the types so we can get the right data.
01920     $types = views_object_types();
01921     // Initialize the display
01922     $this->set_display($display_id);
01923 
01924     // Get the existing configuration
01925     $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
01926 
01927     return isset($fields[$id]) ? $fields[$id] : NULL;
01928   }

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

Get an array of items for the current display.

Definition at line 1902 of file view.inc.

References $display_id, and views_object_types().

01902                                                 {
01903     $this->set_display($display_id);
01904 
01905     if (!isset($display_id)) {
01906       $display_id = $this->current_display;
01907     }
01908 
01909     // Get info about the types so we can get the right data.
01910     $types = views_object_types();
01911     return $this->display[$display_id]->handler->get_option($types[$type]['plural']);
01912   }

view::get_path (  ) 

Get the base path used for this view.

Definition at line 1161 of file view.inc.

References set_display().

Referenced by get_url().

01161                       {
01162     if (!empty($this->override_path)) {
01163       return $this->override_path;
01164     }
01165 
01166     if (empty($this->display_handler)) {
01167       if (!$this->set_display('default')) {
01168         return FALSE;
01169       }
01170     }
01171     return $this->display_handler->get_path();
01172   }

view::get_title (  ) 

Get the view's current title.

This can change depending upon how it was built.

Definition at line 1075 of file view.inc.

References $title, and set_display().

01075                        {
01076     if (empty($this->display_handler)) {
01077       if (!$this->set_display('default')) {
01078         return FALSE;
01079       }
01080     }
01081 
01082     // During building, we might find a title override. If so, use it.
01083     if (!empty($this->build_info['title'])) {
01084       $title = $this->build_info['title'];
01085     }
01086     else {
01087       $title = $this->display_handler->get_option('title');
01088     }
01089 
01090     return $title;
01091   }

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

Get the URL for the current view.

This URL will be adjusted for arguments.

Definition at line 1111 of file view.inc.

References $args, and get_path().

Referenced by _build_arguments().

01111                                                {
01112     if (!isset($path)) {
01113       $path = $this->get_path();
01114     }
01115     if (!isset($args)) {
01116       $args = $this->args;
01117     }
01118     // Don't bother working if there's nothing to do:
01119     if (empty($path) || (empty($args) && strpos($path, '%') === FALSE)) {
01120       return $path;
01121     }
01122 
01123     $pieces = array();
01124     $arguments = isset($arguments) ? $arguments : $this->display_handler->get_option('arguments');
01125     $argument_keys = isset($arguments) ? array_keys($arguments) : array();
01126     $id = current($argument_keys);
01127     foreach (explode('/', $path) as $piece) {
01128       if ($piece != '%') {
01129         $pieces[] = $piece;
01130       }
01131       else {
01132         if (empty($args)) {
01133           // Try to never put % in a url; use the wildcard instead.
01134           if ($id && !empty($arguments[$id]['wildcard'])) {
01135             $pieces[] = $arguments[$id]['wildcard'];
01136           }
01137           else {
01138             $pieces[] = '*'; // gotta put something if there just isn't one.
01139           }
01140 
01141         }
01142         else {
01143           $pieces[] = array_shift($args);
01144         }
01145 
01146         if ($id) {
01147           $id = next($argument_keys);
01148         }
01149       }
01150     }
01151 
01152     if (!empty($args)) {
01153       $pieces = array_merge($pieces, $args);
01154     }
01155     return implode('/', $pieces);
01156   }

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 1622 of file view.inc.

References $field, and views_db_object::load_row().

01622                               {
01623     if (is_array($init)) {
01624       return $this->load_row($init);
01625     }
01626 
01627     if (!$init) {
01628       return;
01629     }
01630 
01631     $schema = drupal_get_schema($this->db_table);
01632 
01633     if (!$schema) {
01634       return;
01635     }
01636 
01637     // Go through our schema and build correlations.
01638     foreach ($schema['fields'] as $field => $info) {
01639       if ($info['type'] == 'serial') {
01640         $this->$field = NULL;
01641       }
01642       if (!isset($this->$field)) {
01643         if (!empty($info['serialize']) && isset($info['serialized default'])) {
01644           $this->$field = unserialize($info['serialized default']);
01645         }
01646         else if (isset($info['default'])) {
01647           $this->$field = $info['default'];
01648         }
01649         else {
01650           $this->$field = '';
01651         }
01652       }
01653     }
01654   }

view::init_display ( reset = FALSE  ) 

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

Definition at line 184 of file view.inc.

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

00184                                         {
00185     // The default display is always the first one in the list.
00186     if (isset($this->current_display)) {
00187       return TRUE;
00188     }
00189 
00190     // Instantiate all displays
00191     foreach (array_keys($this->display) as $id) {
00192       // Correct for shallow cloning
00193       // Often we'll have a cloned view so we don't mess up each other's
00194       // displays, but the clone is pretty shallow and doesn't necessarily
00195       // clone the displays. We can tell this by looking to see if a handler
00196       // has already been set; if it has, but $this->current_display is not
00197       // set, then something is dreadfully wrong.
00198       if (!empty($this->display[$id]->handler)) {
00199         $this->display[$id] = drupal_clone($this->display[$id]);
00200         unset($this->display[$id]->handler);
00201       }
00202       $this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin);
00203       if (!empty($this->display[$id]->handler)) {
00204         // Initialize the new display handler with data.
00205         $this->display[$id]->handler->init($this, $this->display[$id]);
00206         // If this is NOT the default display handler, let it know which is
00207         // since it may well utilize some data from the default.
00208         // This assumes that the 'default' handler is always first. It always
00209         // is. Make sure of it.
00210         if ($id != 'default') {
00211           $this->display[$id]->handler->default_display = &$this->display['default']->handler;
00212         }
00213       }
00214     }
00215 
00216     $this->current_display = 'default';
00217     $this->display_handler = &$this->display['default']->handler;
00218 
00219     return TRUE;
00220   }

view::init_handlers (  ) 

Acquire and attach all of the handlers.

Definition at line 322 of file view.inc.

References _init_handler(), and views_object_types().

Referenced by build(), and build_title().

00322                            {
00323     if (empty($this->inited)) {
00324       foreach (views_object_types() as $key => $info) {
00325         $this->_init_handler($key, $info);
00326       }
00327       $this->inited = TRUE;
00328     }
00329   }

view::init_query (  ) 

Do some common building initialization.

Definition at line 527 of file view.inc.

Referenced by build(), and build_title().

00527                         {
00528     // Create and initialize the query object.
00529     $views_data = views_fetch_data($this->base_table);
00530     $this->base_field = $views_data['table']['base']['field'];
00531     if (!empty($views_data['table']['base']['database'])) {
00532       $this->base_database = $views_data['table']['base']['database'];
00533     }
00534     views_include('query');
00535     $this->query = new views_query($this->base_table, $this->base_field);
00536   }

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 298 of file view.inc.

Referenced by build(), and render().

00298                         {
00299     if (isset($this->style_plugin)) {
00300       return is_object($this->style_plugin);
00301     }
00302 
00303     if (!isset($this->plugin_name)) {
00304       $this->plugin_name = $this->display_handler->get_option('style_plugin');
00305       $this->style_options = $this->display_handler->get_option('style_options');
00306     }
00307 
00308     $this->style_plugin = views_get_plugin('style', $this->plugin_name);
00309 
00310     if (empty($this->style_plugin)) {
00311       return FALSE;
00312     }
00313 
00314     // init the new display handler with data.
00315     $this->style_plugin->init($this, $this->display[$this->current_display], $this->style_options);
00316     return TRUE;
00317   }

view::is_cacheable (  ) 

Is this view cacheable?

Definition at line 1211 of file view.inc.

01211                           {
01212     return $this->is_cacheable;
01213   }

& view::load ( arg,
reset = FALSE 
)

Load a view from the database based upon either vid or name.

This is a static factory method that implements internal caching for view objects.

Parameters:
$arg The name of the view or its internal view id (vid)
$reset If TRUE, reset this entry in the load cache.
Returns:
A view object or NULL if it was not available.

Definition at line 1282 of file view.inc.

References $result, db_objects(), and view().

01282                                        {
01283     static $cache = array();
01284 
01285     // We want a NULL value to return TRUE here, so we can't use isset() or empty().
01286     if (!array_key_exists($arg, $cache) || $reset) {
01287       $where = (is_numeric($arg) ? "vid =  %d" : "name = '%s'");
01288       $data = db_fetch_object(db_query("SELECT * FROM {views_view} WHERE $where", $arg));
01289       if (empty($data)) {
01290         $cache[$arg] = NULL;
01291       }
01292       else {
01293         $view = new view();
01294         $view->load_row($data);
01295         $view->type = t('Normal');
01296         // Load all of our subtables.
01297         foreach ($view->db_objects() as $key) {
01298           $object_name = "views_$key";
01299           $result = db_query("SELECT * FROM {{$object_name}} WHERE vid = %d ORDER BY position", $view->vid);
01300 
01301           while ($data = db_fetch_object($result)) {
01302             $object = new $object_name(FALSE);
01303             $object->load_row($data);
01304 
01305             // Because it can get complicated with this much indirection,
01306             // make a shortcut reference.
01307             $location = &$view->$key;
01308 
01309             // If we have a basic id field, load the item onto the view based on
01310             // this ID, otherwise push it on.
01311             if (!empty($object->id)) {
01312               $location[$object->id] = $object;
01313             }
01314             else {
01315               $location[] = $object;
01316             }
01317           }
01318         }
01319 
01320         $view->loaded = TRUE;
01321         $cache[$arg] = $view;
01322       }
01323     }
01324 
01325     return $cache[$arg];
01326   }

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 1730 of file view.inc.

References $field.

Referenced by views_db_object::init().

01730                            {
01731     $schema = drupal_get_schema($this->db_table);
01732 
01733     // Go through our schema and build correlations.
01734     foreach ($schema['fields'] as $field => $info) {
01735       $this->$field = empty($info['serialize']) ? $data->$field : unserialize(db_decode_blob($data->$field));
01736     }
01737   }

view::load_views (  ) 

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 1335 of file view.inc.

References $result, and db_objects().

01335                         {
01336     $result = db_query("SELECT DISTINCT v.* FROM {views_view} v");
01337     $views = array();
01338     $vids = array();
01339 
01340     // Load all the views.
01341     while ($data = db_fetch_object($result)) {
01342       $view = new view;
01343       $view->load_row($data);
01344       $view->loaded = TRUE;
01345       $view->type = t('Normal');
01346       $views[$view->name] = $view;
01347       $names[$view->vid] = $view->name;
01348     }
01349 
01350     // Stop if we didn't get any views.
01351     if (!$views) {
01352       return array();
01353     }
01354 
01355     $vids = implode(', ', array_keys($names));
01356     // Now load all the subtables:
01357     foreach (view::db_objects() as $key) {
01358       $object_name = "views_$key";
01359       $result = db_query("SELECT * FROM {{$object_name}} WHERE vid IN ($vids) ORDER BY vid, position");
01360 
01361       while ($data = db_fetch_object($result)) {
01362         $object = new $object_name(FALSE);
01363         $object->load_row($data);
01364 
01365         // Because it can get complicated with this much indirection,
01366         // make a shortcut reference.
01367         $location = &$views[$names[$object->vid]]->$key;
01368 
01369         // If we have a basic id field, load the item onto the view based on
01370         // this ID, otherwise push it on.
01371         if (!empty($object->id)) {
01372           $location[$object->id] = $object;
01373         }
01374         else {
01375           $location[] = $object;
01376         }
01377       }
01378     }
01379     return $views;
01380   }

& 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:
A reference to the new handler object.

Definition at line 1843 of file view.inc.

References $title, and views_db_object::add_display().

01843                                                                    {
01844     $id = $this->add_display($type, $title, $id);
01845 
01846     // Create a handler
01847     $this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin);
01848     if (empty($this->display[$id]->handler)) {
01849       // provide a 'default' handler as an emergency. This won't work well but
01850       // it will keep things from crashing.
01851       $this->display[$id]->handler = views_get_plugin('display', 'default');
01852     }
01853 
01854     if (!empty($this->display[$id]->handler)) {
01855       // Initialize the new display handler with data.
01856       $this->display[$id]->handler->init($this, $this->display[$id]);
01857       // If this is NOT the default display handler, let it know which is
01858       if ($id != 'default') {
01859         $this->display[$id]->handler->default_display = &$this->display['default']->handler;
01860       }
01861     }
01862 
01863     return $this->display[$id]->handler;
01864   }

view::post_execute (  ) 

Unset the current view, mostly.

Definition at line 975 of file view.inc.

References $old_view.

Referenced by execute_display(), and preview().

00975                           {
00976     // unset current view so we can be properly destructed later on.
00977     // Return the previous value in case we're an attachment.
00978 
00979     if ($this->old_view) {
00980       $old_view = array_pop($this->old_view);
00981     }
00982 
00983     views_set_current_view(isset($old_view) ? $old_view : FALSE);
00984   }

view::pre_execute ( args = array()  ) 

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

Definition at line 949 of file view.inc.

References $args, $display_id, and set_arguments().

Referenced by execute_display(), and preview().

00949                                         {
00950     $this->old_view[] = views_get_current_view();
00951     views_set_current_view($this);
00952     $display_id = $this->current_display;
00953 
00954     // Let modules modify the view just prior to executing it.
00955     foreach (module_implements('views_pre_view') as $module) {
00956       $function = $module . '_views_pre_view';
00957       $function($this, $display_id, $args);
00958     }
00959 
00960     // Prepare the view with the information we have, but only if we were
00961     // passed arguments, as they may have been set previously.
00962     if ($args) {
00963       $this->set_arguments($args);
00964     }
00965 
00966 //    $this->attach_displays();
00967 
00968     // Allow the display handler to set up for execution
00969     $this->display_handler->pre_execute();
00970   }

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 929 of file view.inc.

References $args, $display_id, post_execute(), pre_execute(), and set_display().

00929                                                         {
00930     if (empty($this->current_display) || $this->current_display != $display_id) {
00931       if (!$this->set_display($display_id)) {
00932         return FALSE;
00933       }
00934     }
00935 
00936     $this->preview = TRUE;
00937     $this->pre_execute($args);
00938     // Preview the view.
00939     $output = $this->display_handler->preview();
00940 
00941     $this->post_execute();
00942     return $output;
00943   }

view::render ( display_id = NULL  ) 

Render this view for display.

Definition at line 799 of file view.inc.

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

00799                                       {
00800     $this->execute($display_id);
00801 
00802     // Check to see if the build failed.
00803     if (!empty($this->build_info['fail'])) {
00804       return;
00805     }
00806 
00807     init_theme();
00808 
00809     $start = views_microtime();
00810     if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) {
00811       $this->start_query_capture();
00812     }
00813 
00814     // Check for already-cached output.
00815     if (!empty($this->live_preview)) {
00816       $cache = FALSE;
00817     }
00818     else {
00819       $cache = $this->display_handler->get_cache_plugin();
00820     }
00821     if ($cache && $cache->cache_get('output')) {
00822       vpr('Used cached output');
00823     }
00824     else {
00825       if ($cache) {
00826         $cache->cache_start();
00827       }
00828 
00829       // Initialize the style plugin.
00830       $this->init_style();
00831 
00832       $this->style_plugin->pre_render($this->result);
00833 
00834       // Let modules modify the view just prior to executing it.
00835       foreach (module_implements('views_pre_render') as $module) {
00836         $function = $module . '_views_pre_render';
00837         $function($this);
00838       }
00839 
00840       // Let the theme play too, because pre render is a very themey thing.
00841       $function = $GLOBALS['theme'] . '_views_pre_render';
00842       if (function_exists($function)) {
00843         $function($this, $this->display_handler->output, $cache);
00844       }
00845 
00846       // Give field handlers the opportunity to perform additional queries
00847       // using the entire resultset prior to rendering.
00848       if ($this->style_plugin->uses_fields()) {
00849         foreach ($this->field as $id => $handler) {
00850           if (!empty($this->field[$id])) {
00851             $this->field[$id]->pre_render($this->result);
00852           }
00853         }
00854       }
00855       $this->display_handler->output = $this->display_handler->render();
00856       if ($cache) {
00857         $cache->cache_set('output');
00858       }
00859     }
00860 
00861     if ($cache) {
00862       $cache->post_render($this->display_handler->output);
00863     }
00864 
00865     // Let modules modify the view output after it is rendered.
00866     foreach (module_implements('views_post_render') as $module) {
00867       $function = $module . '_views_post_render';
00868       $function($this, $this->display_handler->output, $cache);
00869     }
00870 
00871     // Let the theme play too, because post render is a very themey thing.
00872     $function = $GLOBALS['theme'] . '_views_post_render';
00873     if (function_exists($function)) {
00874       $function($this, $this->display_handler->output, $cache);
00875     }
00876 
00877     if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) {
00878       $this->end_query_capture();
00879     }
00880     $this->render_time = views_microtime() - $start;
00881 
00882     return $this->display_handler->output;
00883   }

view::render_exposed_form ( block = FALSE  ) 

Render the exposed filter form.

This actually does more than that; because it's using FAPI, the form will also assign data to the appropriate handlers for use in building the query.

Definition at line 392 of file view.inc.

Referenced by build().

00392                                                {
00393     // Deal with any exposed filters we may have, before building.
00394     $form_state = array(
00395       'view' => &$this,
00396       'display' => &$this->display_handler->display,
00397       'method' => 'get',
00398       'rerender' => TRUE,
00399       'no_redirect' => TRUE,
00400     );
00401 
00402     // Some types of displays (eg. attachments) may wish to use the exposed
00403     // filters of their parent displays instead of showing an additional
00404     // exposed filter form for the attachment as well as that for the parent.
00405     if (!$this->display_handler->displays_exposed() || (!$block && $this->display_handler->get_option('exposed_block'))) {
00406       unset($form_state['rerender']);
00407     }
00408 
00409     if (!empty($this->ajax)) {
00410       $form_state['ajax'] = TRUE;
00411     }
00412 
00413     $output = drupal_build_form('views_exposed_form', $form_state);
00414     if (!empty($form_state['js settings'])) {
00415       $this->js_settings = $form_state['js settings'];
00416     }
00417 
00418     return $output;
00419   }

view::render_field ( field,
row 
)

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

Definition at line 888 of file view.inc.

References $field.

00888                                       {
00889     if (isset($this->field[$field]) && isset($this->result[$row])) {
00890       return $this->field[$field]->advanced_render($this->result[$row]);
00891     }
00892   }

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 1386 of file view.inc.

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

01386                   {
01387     if ($this->vid == 'new') {
01388       $this->vid = NULL;
01389     }
01390 
01391     // If we have no vid or our vid is a string, this is a new view.
01392     if (!empty($this->vid)) {
01393       // remove existing table entries
01394       foreach ($this->db_objects() as $key) {
01395         db_query("DELETE from {views_" . $key . "} WHERE vid = %d", $this->vid);
01396       }
01397     }
01398 
01399     $this->save_row(!empty($this->vid) ? 'vid' : FALSE);
01400 
01401     // Save all of our subtables.
01402     foreach ($this->db_objects() as $key) {
01403       $this->_save_rows($key);
01404     }
01405 
01406     cache_clear_all('views_urls', 'cache_views');
01407     cache_clear_all(); // clear the page cache as well.
01408   }

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 1662 of file view.inc.

References $field.

Referenced by save().

01662                                     {
01663     $schema = drupal_get_schema($this->db_table);
01664     $fields = $defs = $values = $serials = array();
01665 
01666     // Go through our schema and build correlations.
01667     foreach ($schema['fields'] as $field => $info) {
01668       // special case -- skip serial types if we are updating.
01669       if ($info['type'] == 'serial') {
01670         $serials[] = $field;
01671         continue;
01672       }
01673       $fields[] = $field;
01674       switch ($info['type']) {
01675         case 'blob':
01676           $defs[] = '%b';
01677           break;
01678         case 'int':
01679           $defs[] = '%d';
01680           break;
01681         case 'float':
01682         case 'numeric':
01683           $defs[] = '%f';
01684           break;
01685         default:
01686           $defs[] = "'%s'";
01687       }
01688       if (empty($info['serialize'])) {
01689         $values[] = $this->$field;
01690       }
01691       else {
01692         $values[] = serialize($this->$field);
01693       }
01694     }
01695     $query = '';
01696     if (!$update) {
01697       $query = "INSERT INTO {" . $this->db_table . "} (" . implode(', ', $fields) . ') VALUES (' . implode(', ', $defs) . ')';
01698     }
01699     else {
01700       $query = '';
01701       foreach ($fields as $id => $field) {
01702         if ($query) {
01703           $query .= ', ';
01704         }
01705         $query .= $field . ' = ' . $defs[$id];
01706       }
01707       $query = "UPDATE {" . $this->db_table . "} SET " . $query . " WHERE $update = " . $this->$update;
01708     }
01709     db_query($query, $values);
01710 
01711     if ($serials && !$update) {
01712       // get last insert ids and fill them in.
01713       foreach ($serials as $field) {
01714         $this->$field = db_last_insert_id($this->db_table, $field);
01715       }
01716     }
01717   }

view::set_arguments ( args  ) 

Set the arguments that come to this view.

Usually from the URL but possibly from elsewhere.

Definition at line 90 of file view.inc.

References $args.

Referenced by pre_execute().

00090                                 {
00091     $this->args = $args;
00092   }

view::set_current_page ( page  ) 

Change/Set the current page for the pager.

Definition at line 107 of file view.inc.

00107                                    {
00108     $this->pager['current_page'] = $page;
00109   }

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 250 of file view.inc.

References $display_id, choose_display(), and init_display().

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

00250                                            {
00251     // If we have not already initialized the display, do so. But be careful.
00252     if (empty($this->current_display)) {
00253       $this->init_display();
00254 
00255       // If handlers were not initialized, and no argument was sent, set up
00256       // to the default display.
00257       if (empty($display_id)) {
00258         $display_id = 'default';
00259       }
00260     }
00261 
00262     $display_id = $this->choose_display($display_id);
00263 
00264     // If no display id sent in and one wasn't chosen above, we're finished.
00265     if (empty($display_id)) {
00266       return TRUE;
00267     }
00268 
00269     // Ensure the requested display exists.
00270     if (empty($this->display[$display_id])) {
00271       $display_id = 'default';
00272       if (empty($this->display[$display_id])) {
00273         vpr(t('set_display() called with invalid display id @display.', array('@display' => $display_id)));
00274         return FALSE;
00275       }
00276     }
00277 
00278     // Set the current display.
00279     $this->current_display = $display_id;
00280 
00281     // Ensure requested display has a working handler.
00282     if (empty($this->display[$display_id]->handler)) {
00283       return FALSE;
00284     }
00285 
00286     // Set a shortcut
00287     $this->display_handler = &$this->display[$display_id]->handler;
00288 
00289     return TRUE;
00290   }

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 146 of file view.inc.

00146                                        {
00147     $this->exposed_input = $filters;
00148   }

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

Get 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 1936 of file view.inc.

References $display_id, $item, and views_object_types().

Referenced by views_db_object::set_item_option().

01936                                                     {
01937     // Get info about the types so we can get the right data.
01938     $types = views_object_types();
01939     // Initialize the display
01940     $this->set_display($display_id);
01941 
01942     // Get the existing configuration
01943     $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
01944     if (isset($item)) {
01945       $fields[$id] = $item;
01946     }
01947     else {
01948       unset($fields[$id]);
01949     }
01950 
01951     // Store.
01952     $this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
01953   }

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 1962 of file view.inc.

References $display_id, $item, views_db_object::get_item(), and views_db_object::set_item().

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

view::set_items_per_page ( items_per_page  ) 

Set the page size for ranged or pager queries.

Definition at line 97 of file view.inc.

00097                                                {
00098     $this->pager['items_per_page'] = $items_per_page;
00099     if (empty($items_per_page)) {
00100       $this->pager['use_pager'] = FALSE;
00101     }
00102   }

view::set_offset ( offset  ) 

How many records to skip.

This does not function if use_pager is set.

Definition at line 129 of file view.inc.

00129                                {
00130     $this->pager['offset'] = $offset;
00131   }

view::set_pager_element ( pager_element  ) 

The pager element id to use if use_apger is on.

Definition at line 121 of file view.inc.

00121                                              {
00122     $this->pager['element'] = $pager_element;
00123   }

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 138 of file view.inc.

References $use_ajax.

00138                                    {
00139     $this->use_ajax = $use_ajax;
00140   }

view::set_use_pager ( use_pager  ) 

Whether or not the pager should be used.

Definition at line 114 of file view.inc.

00114                                      {
00115     $this->pager['use_pager'] = $use_pager;
00116   }

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 1224 of file view.inc.

Referenced by render().

01224                                  {
01225     global $conf, $queries;
01226     if (empty($conf['dev_query'])) {
01227       $this->fix_dev_query = TRUE;
01228       $conf['dev_query'] = TRUE;
01229     }
01230 
01231     // Record the last query key used; anything already run isn't
01232     // a query that we are interested in.
01233     $this->last_query_key = NULL;
01234 
01235     if (!empty($queries)) {
01236       $keys = array_keys($queries);
01237       $this->last_query_key = array_pop($keys);
01238     }
01239   }

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 1588 of file view.inc.

References $result, and init_display().

01588                       {
01589     $this->init_display();
01590 
01591     $errors = array();
01592 
01593     foreach ($this->display as $id => $display) {
01594       if ($display->handler) {
01595         if (!empty($display->deleted)) {
01596           continue;
01597         }
01598 
01599         $result = $this->display[$id]->handler->validate();
01600         if (!empty($result) && is_array($result)) {
01601           $errors = array_merge($errors, $result);
01602         }
01603       }
01604     }
01605 
01606     return $errors ? $errors : TRUE;
01607   }

view::view (  ) 

Constructor.

Definition at line 57 of file view.inc.

References db_objects().

Referenced by load().

00057                   {
00058     parent::init();
00059     // Make sure all of our sub objects are arrays.
00060     foreach ($this->db_objects() as $object) {
00061       $this->$object = array();
00062     }
00063 
00064     $this->query = new stdClass();
00065   }


Member Data Documentation

view::$pager

Initial value:

 array(
    'use_pager' => FALSE,
    'items_per_page' => 10,
    'element' => 0,
    'offset' => 0,
    'current_page' => 0,
  )

Definition at line 36 of file view.inc.


The documentation for this class was generated from the following file:
Generated on Mon Nov 30 15:06:04 2009 for Views by  doxygen 1.4.7